Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(chromium): do not create default page and context in headless #1247

Merged
merged 3 commits into from
Mar 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/server/chromium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,13 @@ export class Chromium implements BrowserType {
'--mute-audio'
);
}
if (launchType !== 'persistent')
chromeArguments.push('--no-startup-window');
chromeArguments.push(...args);
if (args.every(arg => arg.startsWith('-')))
chromeArguments.push('about:blank');
if (launchType === 'persistent') {
if (args.every(arg => arg.startsWith('-')))
chromeArguments.push('about:blank');
} else {
chromeArguments.push('--no-startup-window');
}

return chromeArguments;
}
Expand Down
16 changes: 16 additions & 0 deletions test/chromium/launcher.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,20 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, p
await rmAsync(downloadsFolder);
});
});

describe('BrowserContext', function() {
it('should not create pages automatically', async function() {
const browser = await playwright.launch();
const browserSession = await browser.createBrowserSession();
const targets = [];
browserSession.on('Target.targetCreated', async ({targetInfo}) => {
if (targetInfo.type !== 'browser')
targets.push(targetInfo);
});
await browserSession.send('Target.setDiscoverTargets', { discover: true });
await browser.newContext();
await browser.close();
expect(targets.length).toBe(0);
});
});
};