diff --git a/lib/cjs/index.js b/lib/cjs/index.js index 70f5254..6b482fa 100644 --- a/lib/cjs/index.js +++ b/lib/cjs/index.js @@ -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, }); diff --git a/lib/esm/index.mjs b/lib/esm/index.mjs index fa6e3e0..803507f 100644 --- a/lib/esm/index.mjs +++ b/lib/esm/index.mjs @@ -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;