mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
feat(Launcher): allow the default arguments to be overridden (#1623)
This patch: - adds `puppeteer.defaultArgs()` method to get default arguments that are used to launch chrome - adds `ignoreDefaultArgs` option to `puppeteer.launch` to avoid using default puppeteer arguments Fixes #872
This commit is contained in:
parent
f8040cb2a2
commit
8a40cd5eef
@ -10,6 +10,7 @@
|
||||
- [Environment Variables](#environment-variables)
|
||||
- [class: Puppeteer](#class-puppeteer)
|
||||
* [puppeteer.connect(options)](#puppeteerconnectoptions)
|
||||
* [puppeteer.defaultArgs()](#puppeteerdefaultargs)
|
||||
* [puppeteer.executablePath()](#puppeteerexecutablepath)
|
||||
* [puppeteer.launch([options])](#puppeteerlaunchoptions)
|
||||
- [class: Browser](#class-browser)
|
||||
@ -246,6 +247,9 @@ puppeteer.launch().then(async browser => {
|
||||
|
||||
This methods attaches Puppeteer to an existing Chromium instance.
|
||||
|
||||
#### puppeteer.defaultArgs()
|
||||
- returns: <[Array]<[string]>> The default flags that Chromium will be launched with.
|
||||
|
||||
#### puppeteer.executablePath()
|
||||
- returns: <[string]> A path where Puppeteer expects to find bundled Chromium. Chromium might not exist there if the download was skipped with [`PUPPETEER_SKIP_CHROMIUM_DOWNLOAD`](#environment-variables).
|
||||
|
||||
@ -256,6 +260,7 @@ This methods attaches Puppeteer to an existing Chromium instance.
|
||||
- `executablePath` <[string]> Path to a Chromium or Chrome executable to run instead of bundled Chromium. If `executablePath` is a relative path, then it is resolved relative to [current working directory](https://nodejs.org/api/process.html#process_process_cwd).
|
||||
- `slowMo` <[number]> Slows down Puppeteer operations by the specified amount of milliseconds. Useful so that you can see what is going on.
|
||||
- `args` <[Array]<[string]>> Additional arguments to pass to the browser instance. List of Chromium flags can be found [here](http://peter.sh/experiments/chromium-command-line-switches/).
|
||||
- `ignoreDefaultArgs` <[boolean]> Do not use [`puppeteer.defaultArgs()`](#puppeteerdefaultargs). Dangerous option; use with care. Defaults to `false`.
|
||||
- `handleSIGINT` <[boolean]> Close browser process on Ctrl-C. Defaults to `true`.
|
||||
- `handleSIGTERM` <[boolean]> Close browser process on SIGTERM. Defaults to `true`.
|
||||
- `handleSIGHUP` <[boolean]> Close browser process on SIGHUP. Defaults to `true`.
|
||||
|
@ -61,10 +61,13 @@ class Launcher {
|
||||
static async launch(options) {
|
||||
options = Object.assign({}, options || {});
|
||||
let temporaryUserDataDir = null;
|
||||
const chromeArguments = [].concat(DEFAULT_ARGS);
|
||||
const chromeArguments = [];
|
||||
if (!options.ignoreDefaultArgs)
|
||||
chromeArguments.push(...DEFAULT_ARGS);
|
||||
|
||||
if (options.appMode)
|
||||
options.headless = false;
|
||||
else
|
||||
else if (!options.ignoreDefaultArgs)
|
||||
chromeArguments.push(...AUTOMATION_ARGS);
|
||||
|
||||
if (!options.args || !options.args.some(arg => arg.startsWith('--user-data-dir'))) {
|
||||
@ -172,6 +175,13 @@ class Launcher {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {!Array<string>}
|
||||
*/
|
||||
static defaultArgs() {
|
||||
return DEFAULT_ARGS.concat(AUTOMATION_ARGS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {string}
|
||||
*/
|
||||
|
@ -39,6 +39,13 @@ class Puppeteer {
|
||||
static executablePath() {
|
||||
return Launcher.executablePath();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {!Array<string>}
|
||||
*/
|
||||
static defaultArgs() {
|
||||
return Launcher.defaultArgs();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Puppeteer;
|
||||
|
@ -202,6 +202,10 @@ describe('Puppeteer', function() {
|
||||
rm(userDataDir);
|
||||
expect(cookie).toBe('foo=true');
|
||||
});
|
||||
it('should return the default chrome arguments', async() => {
|
||||
const args = puppeteer.defaultArgs();
|
||||
expect(args).toContain('--no-first-run');
|
||||
});
|
||||
});
|
||||
describe('Puppeteer.connect', function() {
|
||||
it('should be able to connect multiple times to the same browser', async({server}) => {
|
||||
|
Loading…
Reference in New Issue
Block a user