From b8df8bdf4a1ecd3768cf7edf6b920814daedb904 Mon Sep 17 00:00:00 2001 From: Yaniv Efraim Date: Sat, 26 May 2018 03:26:40 +0300 Subject: [PATCH] feat(launcher): launch browser with 'about:blank' by default (#2594) fixes #2402 --- lib/Launcher.js | 3 +++ test/puppeteer.spec.js | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/Launcher.js b/lib/Launcher.js index b3866dd4..3311e74e 100644 --- a/lib/Launcher.js +++ b/lib/Launcher.js @@ -93,6 +93,9 @@ class Launcher { '--mute-audio' ); } + if (!options.ignoreDefaultArgs && Array.isArray(options.args) && options.args.every(arg => arg.startsWith('-'))) + chromeArguments.push('about:blank'); + let chromeExecutable = options.executablePath; if (typeof chromeExecutable !== 'string') { const browserFetcher = new BrowserFetcher(); diff --git a/test/puppeteer.spec.js b/test/puppeteer.spec.js index e40da803..f5b144e4 100644 --- a/test/puppeteer.spec.js +++ b/test/puppeteer.spec.js @@ -264,6 +264,28 @@ module.exports.addTests = function({testRunner, expect, PROJECT_ROOT, defaultBro await page.close(); await browser.close(); }); + it('should have default url when launching browser', async function() { + const browser = await puppeteer.launch(defaultBrowserOptions); + const pages = (await browser.pages()).map(page => page.url()); + expect(pages).toEqual(['about:blank']); + await browser.close(); + }); + it('should have default url when launching browser with headless:false', async function() { + const options = Object.assign({}, defaultBrowserOptions, {headless: false}); + const browser = await puppeteer.launch(options); + const pages = (await browser.pages()).map(page => page.url()); + expect(pages).toEqual(['about:blank']); + await browser.close(); + }); + it('should have custom url when launching browser', async function({server}) { + const customUrl = server.PREFIX + '/empty.html'; + const options = Object.assign({}, defaultBrowserOptions); + options.args = [customUrl].concat(options.args); + const browser = await puppeteer.launch(options); + const pages = (await browser.pages()).map(page => page.url()); + expect(pages).toEqual([customUrl]); + await browser.close(); + }); }); describe('Puppeteer.connect', function() { it('should be able to connect multiple times to the same browser', async({server}) => {