Skip to content

Commit

Permalink
Merge pull request #139 from rtritto/disable-automation-controlled
Browse files Browse the repository at this point in the history
Improve Disable Features flag
  • Loading branch information
mdervisaygan authored Dec 27, 2024
2 parents b0f7061 + 085bc6c commit 5eb38b3
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 50 deletions.
55 changes: 30 additions & 25 deletions lib/cjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,38 @@ async function connect({
}
}

let chromeFlags;
if (ignoreAllFlags === true) {
chromeFlags = [
...args,
...(headless !== false ? [`--headless=${headless}`] : []),
...(proxy && proxy.host && proxy.port
? [`--proxy-server=${proxy.host}:${proxy.port}`]
: []),
];
} else {
// Default flags: https://github.com/GoogleChrome/chrome-launcher/blob/main/src/flags.ts
const flags = Launcher.defaultFlags();
// Add AutomationControlled to "disable-features" flag
const indexDisableFeatures = flags.findIndex((flag) => flag.startsWith('--disable-features'));
flags[indexDisableFeatures] = `${flags[indexDisableFeatures]},AutomationControlled`;
// Remove "disable-component-update" flag
const indexComponentUpdateFlag = flags.findIndex((flag) => flag.startsWith('--disable-component-update'));
flags.splice(indexComponentUpdateFlag, 1);
chromeFlags = [
...flags,
...args,
...(headless !== false ? [`--headless=${headless}`] : []),
...(proxy && proxy.host && proxy.port
? [`--proxy-server=${proxy.host}:${proxy.port}`]
: []),
"--no-sandbox",
"--disable-dev-shm-usage",
];
}
const chrome = await launch({
ignoreDefaultFlags: true,
chromeFlags: [
...(ignoreAllFlags === true
? [
...(proxy && proxy.host && proxy.port
? [`--proxy-server=${proxy.host}:${proxy.port}`]
: []),
...args,
...(headless !== false ? [`--headless=${headless}`] : []),
]
: [
...Launcher.defaultFlags().filter(
(item) =>
!item.includes("--disable-features") &&
!item.includes("component-update")
),
...args,
...(headless !== false ? [`--headless=${headless}`] : []),
...(proxy && proxy.host && proxy.port
? [`--proxy-server=${proxy.host}:${proxy.port}`]
: []),
"--disable-features=Translate,OptimizationHints,MediaRouter,DialMediaRouteProvider,CalculateNativeWinOcclusion,InterestFeedContentSuggestions,CertificateTransparencyComponentUpdater,AutofillServerCommunication,PrivacySandboxSettings4,AutomationControlled",
"--no-sandbox",
"--disable-dev-shm-usage",
]),
],
chromeFlags,
...customConfig,
});

Expand Down
55 changes: 30 additions & 25 deletions lib/esm/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,38 @@ export async function connect({
}
}

let chromeFlags;
if (ignoreAllFlags === true) {
chromeFlags = [
...args,
...(headless !== false ? [`--headless=${headless}`] : []),
...(proxy && proxy.host && proxy.port
? [`--proxy-server=${proxy.host}:${proxy.port}`]
: []),
];
} else {
// Default flags: https://github.com/GoogleChrome/chrome-launcher/blob/main/src/flags.ts
const flags = Launcher.defaultFlags();
// Add AutomationControlled to "disable-features" flag
const indexDisableFeatures = flags.findIndex((flag) => flag.startsWith('--disable-features'));
flags[indexDisableFeatures] = `${flags[indexDisableFeatures]},AutomationControlled`;
// Remove "disable-component-update" flag
const indexComponentUpdateFlag = flags.findIndex((flag) => flag.startsWith('--disable-component-update'));
flags.splice(indexComponentUpdateFlag, 1);
chromeFlags = [
...flags,
...args,
...(headless !== false ? [`--headless=${headless}`] : []),
...(proxy && proxy.host && proxy.port
? [`--proxy-server=${proxy.host}:${proxy.port}`]
: []),
"--no-sandbox",
"--disable-dev-shm-usage",
];
}
const chrome = await launch({
ignoreDefaultFlags: true,
chromeFlags: [
...(ignoreAllFlags === true
? [
...(proxy && proxy.host && proxy.port
? [`--proxy-server=${proxy.host}:${proxy.port}`]
: []),
...args,
...(headless !== false ? [`--headless=${headless}`] : []),
]
: [
...Launcher.defaultFlags().filter(
(item) =>
!item.includes("--disable-features") &&
!item.includes("component-update")
),
...args,
...(headless !== false ? [`--headless=${headless}`] : []),
...(proxy && proxy.host && proxy.port
? [`--proxy-server=${proxy.host}:${proxy.port}`]
: []),
"--disable-features=Translate,OptimizationHints,MediaRouter,DialMediaRouteProvider,CalculateNativeWinOcclusion,InterestFeedContentSuggestions,CertificateTransparencyComponentUpdater,AutofillServerCommunication,PrivacySandboxSettings4,AutomationControlled",
"--no-sandbox",
"--disable-dev-shm-usage",
]),
],
chromeFlags,
...customConfig,
});
let pextra = null;
Expand Down

0 comments on commit 5eb38b3

Please sign in to comment.