Skip to content

Commit

Permalink
Merge pull request #1 from TechQuery/master
Browse files Browse the repository at this point in the history
[ Refactor ]  Make this project more engineering
  • Loading branch information
autonome committed Apr 19, 2018
2 parents ca887f5 + bf104bc commit c6cdbe5
Show file tree
Hide file tree
Showing 26 changed files with 4,193 additions and 116 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 4
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
31 changes: 31 additions & 0 deletions .eslintrc.json
@@ -0,0 +1,31 @@
{
"env": {
"es6": true,
"node": true,
"browser": true,
"mocha": true
},
"parserOptions": {
"ecmaVersion": 8
},
"extends": "eslint:recommended",
"rules": {
"indent": [
"error", 4, {"SwitchCase": 1}
],
"linebreak-style": [
"error", "unix"
],
"quotes": [
"error", "single"
],
"semi": [
"error", "always"
],
"no-console": [
"error", {
"allow": ["info", "warn", "error", "time", "timeEnd"]
}
]
}
}
62 changes: 62 additions & 0 deletions .gitignore
@@ -0,0 +1,62 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# Editor & IDE configuration
.vscode/
.idea/
5 changes: 5 additions & 0 deletions .npmignore
@@ -0,0 +1,5 @@
build/
docs/
test/
.editorconfig
.eslintrc.json
56 changes: 28 additions & 28 deletions README.md
@@ -1,31 +1,16 @@
# Puppeteer for Firefox

I needed to run some tests against both Chrome and Firefox. Because I am lazy, I only wanted to write the harness code once.
Headless Firefox NodeJS API based on [FoxDriver](https://github.com/saucelabs/foxdriver/) (written by the wonderful folks at [Sauce Labs](https://saucelabs.com/)), which is compatible with [Puppeteer API](https://github.com/GoogleChrome/puppeteer/).

So I took [Foxdriver](https://github.com/saucelabs/foxdriver), written by the wonderful folks at [Sauce Labs](https://saucelabs.com/), and wrapped the [Puppeteer API](https://github.com/GoogleChrome/puppeteer/) around it.
[![NPM](https://nodei.co/npm/puppeteer-fx.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/puppeteer-fx/)

Well, just a tiny bit of it... enough to:

* Launch Firefox
* Open a URL
* Evaluate JS in the console of the page

I'll probably add more as I hit more functionality that I need.
## Supported APIs

Happy to accept PRs if you find this useful and want to add more API coverage.
Execute `npm run help` for details.

## Supported APIs

* puppeteer
* launch()
* headless
* userDataDir
* browser
* newPage()
* close()
* page
* goto()
* evaluate()

## Extra APIs

Expand All @@ -39,32 +24,41 @@ Network Throttling
* latency: integer, in milliseconds, defaults to 100



## Installation

It's on NPM, so add `puppeteer-fx` to your dependencies in package.json, or:

```bash

```Shell
npm install puppeteer-fx
```


## Example

```
const puppeteerFx = require('./puppeteer-fx');
const url = 'https://mozilla.github.io/arewefastyet-speedometer/2.0/';
const browser = await puppeteer.launch({headless: false});
```JavaScript
const puppeteer = require('./puppeteer-fx');

(async () => {

const page = await browser.newPage();
await page.goto(url);
const browser = await puppeteer.launch({headless: false});

page.evaluate('document.querySelector(\'section#home div.buttons button\').click()');
const page = await browser.newPage();

await page.goto('https://mozilla.github.io/arewefastyet-speedometer/2.0/');

await page.evaluate(
'document.querySelector("section#home div.buttons button").click()'
);
})();
```


## Profiles

user.js

```JavaScript
user_pref("devtools.chrome.enabled", true);
user_pref("devtools.debugger.prompt-connection", false);
user_pref("devtools.debugger.remote-enabled", true);
Expand All @@ -79,6 +73,12 @@ user_pref("toolkit.telemetry.prompted", true);
user_pref("browser.rights.override", true);
user_pref("browser.startup.homepage_override.mstone", "ignore");
user_pref("browser.shell.checkDefaultBrowser", false);
```

https://github.com/saucelabs/foxdriver/blob/master/lib/config/profile/prefs.js



## Similar works

- [Puppeteer-IE](https://techquery.github.io/Puppeteer-IE/)
23 changes: 23 additions & 0 deletions build/beautifyDoc.js
@@ -0,0 +1,23 @@
#! /usr/bin/env node

const FS = require('fs-extra');

const FS_match = require('fs-match'), Beautify = require('js-beautify').html;


console.log();

console.time('Beautify-Doc');

Promise.all(
FS_match('.*\\.html', process.argv[2] || '.').map(async function (file) {

console.log(file = file.trim());

const code = await FS.readFile( file );

return await FS.writeFile(
file, Beautify(code.toString('utf-8'), {'max-preserve-newlines': 3})
);
})
).then( console.timeEnd.bind(console, 'Beautify-Doc') );
20 changes: 20 additions & 0 deletions build/document.json
@@ -0,0 +1,20 @@
{
"opts": {
"recurse": true,
"readme": "ReadMe.md",
"template": "node_modules/docdash",
"destination": "docs/",
"verbose": true
},
"templates": {
"default": {
"includeDate": false
}
},
"plugins": [
"plugins/markdown", "node_modules/jsdoc-inheritance-diagram"
],
"markdown": {
"hardwrap": true
}
}

0 comments on commit c6cdbe5

Please sign in to comment.