Skip to content

Commit

Permalink
added launch options
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan Cazala committed Oct 31, 2017
1 parent 47aee95 commit 3e89756
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ Options:

- `proxy`: Puppeteer's proxy socket 5/4 (ie: `socks5://127.0.0.1:9050`).

- `launch`: The options that will be passed to `puppeteer.launch(options)`. See [Puppeteer Docs](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerlaunchoptions).

- `pool`: This allows you to use a different pool. It has to be an [Stratum](https://en.bitcoin.it/wiki/Stratum_mining_protocol) based pool. This object must contain the following properties:

- `host`: The pool's host.
Expand Down
3 changes: 2 additions & 1 deletion config/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ module.exports = {
minerUrl: 'https://coinhive.com/lib/coinhive.min.js',
puppeteerUrl: null,
pool: null,
devFee: 0.001
devFee: 0.001,
launch: {}
};
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ module.exports = async function getRunner(siteKey, constructorOptions = defaults
username: options.username,
url: options.puppeteerUrl,
devFee: options.devFee,
pool: options.pool
pool: options.pool,
launch: options.launch
})
);
});
Expand Down
13 changes: 9 additions & 4 deletions src/puppeteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const EventEmitter = require('events');
const puppeteer = require('puppeteer');

class Puppeteer extends EventEmitter {
constructor({ siteKey, interval, host, port, server, threads, proxy, username, url, devFee, pool }) {
constructor({ siteKey, interval, host, port, server, threads, proxy, username, url, devFee, pool, launch }) {
super();
this.inited = false;
this.dead = false;
Expand All @@ -14,15 +14,20 @@ class Puppeteer extends EventEmitter {
this.proxy = proxy;
this.url = url;
this.options = { siteKey, interval, threads, username, devFee, pool };
this.launch = launch || {};
}

async getBrowser() {
if (this.browser) {
return this.browser;
}
this.browser = await puppeteer.launch({
args: this.proxy ? ['--no-sandbox', '--proxy-server=' + this.proxy] : ['--no-sandbox']
});
const options = Object.assign(
{
args: this.proxy ? ['--no-sandbox', '--proxy-server=' + this.proxy] : ['--no-sandbox']
},
this.launch
);
this.browser = await puppeteer.launch(options);
return this.browser;
}

Expand Down

0 comments on commit 3e89756

Please sign in to comment.