Skip to content

Commit

Permalink
Steal chromium settings from nodejs lib
Browse files Browse the repository at this point in the history
  • Loading branch information
brianfeucht committed Jan 3, 2024
1 parent b918298 commit 29b4ecb
Showing 1 changed file with 55 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,61 @@ namespace HeadlessChromium.Puppeteer.Lambda.Dotnet
{
public class HeadlessChromiumPuppeteerLauncher
{
public static string[] DefaultChromeArgs = new[]
// Stolen from https://github.com/Sparticuz/chromium/blob/master/source/index.ts
public static string[] DefaultChromeArgs = new[]
{
"--disable-background-timer-throttling",
"--disable-breakpad",
"--disable-client-side-phishing-detection",
"--disable-cloud-import",
"--disable-default-apps",
"--disable-dev-shm-usage",
"--disable-extensions",
"--disable-gesture-typing",
"--disable-hang-monitor",
"--disable-infobars",
"--disable-notifications",
"--disable-offer-store-unmasked-wallet-cards",
"--disable-offer-upload-credit-cards",
"--disable-popup-blocking",
"--disable-print-preview",
"--disable-prompt-on-repost",
"--disable-setuid-sandbox",
"--disable-speech-api",
"--disable-sync",
"--disable-tab-for-desktop-share",
"--disable-translate",
"--disable-voice-input",
"--disable-wake-on-wifi",
"--disk-cache-size=33554432",
"--enable-async-dns",
"--enable-simple-cache-backend",
"--enable-tcp-fast-open",
"--enable-webgl",
"--hide-scrollbars",
"--ignore-gpu-blacklist",
"--media-cache-size=33554432",
"--metrics-recording-only",
"--mute-audio",
"--no-default-browser-check",
"--no-first-run",
"--no-pings",
"--no-sandbox",
"--no-zygote",
"--password-store=basic",
"--prerender-from-omnibox=disabled",
"--use-gl=swiftshader",
"--use-mock-keychain",
"--single-process",
// puppeteerFlags
"--allow-pre-commit-input",
"--disable-background-networking",
"--disable-background-timer-throttling",
"--disable-backgrounding-occluded-windows",
"--disable-breakpad",
"--disable-client-side-phishing-detection",
"--disable-component-extensions-with-background-pages",
"--disable-component-update",
"--disable-default-apps",
"--disable-dev-shm-usage",
"--disable-extensions",
"--disable-hang-monitor",
"--disable-ipc-flooding-protection",
"--disable-popup-blocking",
"--disable-prompt-on-repost",
"--disable-renderer-backgrounding",
"--disable-sync",
"--enable-automation",
"--export-tagged-pdf",
"--force-color-profile=srgb",
"--metrics-recording-only",
"--no-first-run",
"--password-store=basic",
"--use-mock-keychain",
// chromiumFlags
"--disable-domain-reliability", // https://github.com/GoogleChrome/chrome-launcher/blob/main/docs/chrome-flags-for-tools.md#background-networking
"--disable-print-preview", // https://source.chromium.org/search?q=lang:cpp+symbol:kDisablePrintPreview&ss=chromium
"--disable-speech-api", // https://source.chromium.org/search?q=lang:cpp+symbol:kDisableSpeechAPI&ss=chromium
"--disk-cache-size=33554432", // https://source.chromium.org/search?q=lang:cpp+symbol:kDiskCacheSize&ss=chromium
"--mute-audio", // https://source.chromium.org/search?q=lang:cpp+symbol:kMuteAudio&ss=chromium
"--no-default-browser-check", // https://source.chromium.org/search?q=lang:cpp+symbol:kNoDefaultBrowserCheck&ss=chromium
"--no-pings", // https://source.chromium.org/search?q=lang:cpp+symbol:kNoPings&ss=chromium
"--single-process", // Needs to be single-process to avoid `prctl(PR_SET_NO_NEW_PRIVS) failed` error
// graphicsFlags
"--hide-scrollbars", // https://source.chromium.org/search?q=lang:cpp+symbol:kHideScrollbars&ss=chromium
"--ignore-gpu-blocklist", // https://source.chromium.org/search?q=lang:cpp+symbol:kIgnoreGpuBlocklist&ss=chromium
"--in-process-gpu", // https://source.chromium.org/search?q=lang:cpp+symbol:kInProcessGPU&ss=chromium
"--window-size=1920,1080", // https://source.chromium.org/search?q=lang:cpp+symbol:kWindowSize&ss=chromium
// insureFlags
"--allow-running-insecure-content", // https://source.chromium.org/search?q=lang:cpp+symbol:kAllowRunningInsecureContent&ss=chromium
"--disable-setuid-sandbox", // https://source.chromium.org/search?q=lang:cpp+symbol:kDisableSetuidSandbox&ss=chromium
"--disable-site-isolation-trials", // https://source.chromium.org/search?q=lang:cpp+symbol:kDisableSiteIsolation&ss=chromium
"--disable-web-security", // https://source.chromium.org/search?q=lang:cpp+symbol:kDisableWebSecurity&ss=chromium
"--no-sandbox", // https://source.chromium.org/search?q=lang:cpp+symbol:kNoSandbox&ss=chromium
"--no-zygote", // https://source.chromium.org/search?q=lang:cpp+symbol:kNoZygote&ss=chromium
// disabled features merge both chrome and puppeteer
"--disable-features=AudioServiceOutOfProcess,IsolateOrigins,site-per-process,Translate,BackForwardCache,AcceptCHFrame,MediaRouter,OptimizationHints",
// enabled features merge both chrome and puppteteer
"--enabled-features=NetworkServiceInProcess2,SharedArrayBuffer",
// Others
"--headless"
};

private readonly ILoggerFactory loggerFactory;
Expand All @@ -74,6 +84,7 @@ public async Task<IBrowser> LaunchAsync(string[] chromeArgs)
{
ExecutablePath = chromeLocation,
Args = chromeArgs,
IgnoreDefaultArgs = true,
Headless = true
};

Expand Down

0 comments on commit 29b4ecb

Please sign in to comment.