Skip to content
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
15 changes: 15 additions & 0 deletions src/extension-runners/chromium.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,21 @@ export class ChromiumExtensionRunner {
chromeFlags.push(...this.params.args);
}

// `--remote-debugging-pipe` results in `navigator.webdriver == true` in
// the launched Chromium instance (unless a Chromium session exists
// already, in which case the existing session is used, which typically
// has `navigator.webdriver == false`). This breaks websites with bot
// detection features. The following flag prevents this.
// Only pass this flag if `--enable-blink-features=AutomationControlled`
// is not passed.
if (
!chromeFlags.some((flag) =>
/^--enable-blink-features=(.*,)?AutomationControlled(,|$)/.test(flag),
)
) {
chromeFlags.push('--disable-blink-features=AutomationControlled');
}

// eslint-disable-next-line prefer-const
let { userDataDir, profileDirName } =
await ChromiumExtensionRunner.getProfilePaths(
Expand Down
36 changes: 36 additions & 0 deletions tests/unit/test-extension-runners/test.chromium.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ describe('util/extension-runners/chromium', async () => {
...DEFAULT_CHROME_FLAGS,
'--remote-debugging-pipe',
'--enable-unsafe-extension-debugging',
'--disable-blink-features=AutomationControlled',
],
startingUrl: undefined,
});
Expand Down Expand Up @@ -227,6 +228,7 @@ describe('util/extension-runners/chromium', async () => {
...DEFAULT_CHROME_FLAGS,
'--remote-debugging-pipe',
'--enable-unsafe-extension-debugging',
'--disable-blink-features=AutomationControlled',
],
startingUrl: undefined,
});
Expand All @@ -250,6 +252,7 @@ describe('util/extension-runners/chromium', async () => {
...DEFAULT_CHROME_FLAGS,
'--remote-debugging-pipe',
'--enable-unsafe-extension-debugging',
'--disable-blink-features=AutomationControlled',
'url2',
'url3',
],
Expand Down Expand Up @@ -281,6 +284,7 @@ describe('util/extension-runners/chromium', async () => {
'--arg1',
'arg2',
'--arg3',
'--disable-blink-features=AutomationControlled',
'url2',
'url3',
],
Expand All @@ -290,6 +294,32 @@ describe('util/extension-runners/chromium', async () => {
await runnerInstance.exit();
});

it("doesn't disable `AutomationControlled` when corresponding arg is passed", async () => {
// If the `--enable-blink-features=AutomationControlled` flag is passed,
// `--disable-blink-features=AutomationControlled` should not be passed.
const { params } = prepareExtensionRunnerParams({
params: {
args: ['--enable-blink-features=CSSVariables,AutomationControlled'],
},
});

const runnerInstance = new ChromiumExtensionRunner(params);
await runnerInstance.run();

sinon.assert.calledWithMatch(params.chromiumLaunch, {
ignoreDefaultFlags: true,
chromePath: undefined,
chromeFlags: [
...DEFAULT_CHROME_FLAGS,
'--remote-debugging-pipe',
'--enable-unsafe-extension-debugging',
'--enable-blink-features=CSSVariables,AutomationControlled',
],
});

await runnerInstance.exit();
});

it('does use a random user-data-dir', async () => {
const { params } = prepareExtensionRunnerParams({
params: {},
Expand Down Expand Up @@ -334,6 +364,7 @@ describe('util/extension-runners/chromium', async () => {
...DEFAULT_CHROME_FLAGS,
'--remote-debugging-pipe',
'--enable-unsafe-extension-debugging',
'--disable-blink-features=AutomationControlled',
],
startingUrl: undefined,
});
Expand Down Expand Up @@ -375,6 +406,7 @@ describe('util/extension-runners/chromium', async () => {
...DEFAULT_CHROME_FLAGS,
'--remote-debugging-pipe',
'--enable-unsafe-extension-debugging',
'--disable-blink-features=AutomationControlled',
'--profile-directory=profile',
],
startingUrl: undefined,
Expand Down Expand Up @@ -417,6 +449,7 @@ describe('util/extension-runners/chromium', async () => {
...DEFAULT_CHROME_FLAGS,
'--remote-debugging-pipe',
'--enable-unsafe-extension-debugging',
'--disable-blink-features=AutomationControlled',
`--profile-directory=${profileDirName}`,
],
startingUrl: undefined,
Expand Down Expand Up @@ -512,6 +545,7 @@ describe('util/extension-runners/chromium', async () => {
...DEFAULT_CHROME_FLAGS,
'--remote-debugging-pipe',
'--enable-unsafe-extension-debugging',
'--disable-blink-features=AutomationControlled',
'--profile-directory=profile',
],
startingUrl: undefined,
Expand Down Expand Up @@ -548,6 +582,7 @@ describe('util/extension-runners/chromium', async () => {
...DEFAULT_CHROME_FLAGS,
'--remote-debugging-pipe',
'--enable-unsafe-extension-debugging',
'--disable-blink-features=AutomationControlled',
],
startingUrl: undefined,
});
Expand All @@ -558,6 +593,7 @@ describe('util/extension-runners/chromium', async () => {
...DEFAULT_CHROME_FLAGS,
'--remote-debugging-pipe',
'--load-extension=/fake/sourceDir',
'--disable-blink-features=AutomationControlled',
],
startingUrl: undefined,
});
Expand Down