Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ulixee
GitHub Repository: ulixee/secret-agent
Path: blob/main/plugins/default-browser-emulator/lib/helpers/configureBrowserLaunchArgs.ts
1030 views
1
import * as Path from 'path';
2
import * as os from 'os';
3
import BrowserEngine from '@secret-agent/plugin-utils/lib/BrowserEngine';
4
import { defaultScreen } from '../Viewports';
5
6
let sessionDirCounter = 0;
7
8
export function configureBrowserLaunchArgs(
9
engine: BrowserEngine,
10
options: {
11
showBrowser?: boolean;
12
disableGpu?: boolean;
13
disableDevtools?: boolean;
14
},
15
): void {
16
engine.launchArguments.push(
17
'--disable-background-networking', // Disable various background network services, including extension updating,safe browsing service, upgrade detector, translate, UMA
18
'--enable-features=NetworkService,NetworkServiceInProcess',
19
'--disable-background-timer-throttling', // Disable timers being throttled in background pages/tabs
20
'--disable-backgrounding-occluded-windows',
21
'--disable-breakpad', // Disable crashdump collection (reporting is already disabled in Chromium)
22
'--disable-client-side-phishing-detection', // Disables client-side phishing detection.
23
'--disable-domain-reliability', // Disables Domain Reliability Monitoring, which tracks whether the browser has difficulty contacting Google-owned sites and uploads reports to Google.
24
'--disable-default-apps', // Disable installation of default apps on first run
25
'--disable-dev-shm-usage', // https://github.com/GoogleChrome/puppeteer/issues/1834
26
'--disable-extensions', // Disable all chrome extensions.
27
'--disable-features=PaintHolding,TranslateUI,site-per-process,OutOfBlinkCors,DestroyProfileOnBrowserClose', // site-per-process = Disables OOPIF, OutOfBlinkCors = Disables feature in chrome80/81 for out of process cors
28
'--disable-blink-features=AutomationControlled',
29
'--disable-hang-monitor',
30
'--disable-ipc-flooding-protection', // Some javascript functions can be used to flood the browser process with IPC. By default, protection is on to limit the number of IPC sent to 10 per second per frame.
31
'--disable-prompt-on-repost', // Reloading a page that came from a POST normally prompts the user.
32
'--disable-renderer-backgrounding', // This disables non-foreground tabs from getting a lower process priority This doesn't (on its own) affect timers or painting behavior. karma-chrome-launcher#123
33
'--disable-sync', // Disable syncing to a Google account
34
35
'--force-color-profile=srgb', // Force all monitors to be treated as though they have the specified color profile.
36
'--use-gl=any', // Select which implementation of GL the GPU process should use. Options are: desktop: whatever desktop OpenGL the user has installed (Linux and Mac default). egl: whatever EGL / GLES2 the user has installed (Windows default - actually ANGLE). swiftshader: The SwiftShader software renderer.
37
'--disable-partial-raster', // https://crbug.com/919955
38
'--disable-skia-runtime-opts', // Do not use runtime-detected high-end CPU optimizations in Skia.
39
40
'--incognito',
41
42
'--use-fake-device-for-media-stream',
43
44
'--no-default-browser-check', // Disable the default browser check, do not prompt to set it as such
45
'--metrics-recording-only', // Disable reporting to UMA, but allows for collection
46
'--no-first-run', // Skip first run wizards
47
48
// '--enable-automation', BAB - disable because adds infobar, stops auto-reload on network errors (using other flags)
49
'--enable-auto-reload', // Enable auto-reload of error pages.
50
51
'--password-store=basic', // Avoid potential instability of using Gnome Keyring or KDE wallet.
52
'--use-mock-keychain', // Use mock keychain on Mac to prevent blocking permissions dialogs
53
'--allow-running-insecure-content',
54
55
`--window-size=${defaultScreen.width},${defaultScreen.height}`,
56
57
// don't leak private ip
58
'--force-webrtc-ip-handling-policy=default_public_interface_only',
59
'--no-startup-window',
60
);
61
62
if (options.showBrowser) {
63
const dataDir = Path.join(
64
os.tmpdir(),
65
engine.fullVersion.replace('.', '-'),
66
`${String(Date.now()).substr(0, 10)}-${(sessionDirCounter += 1)}`,
67
);
68
engine.launchArguments.push(`--user-data-dir=${dataDir}`); // required to allow multiple browsers to be headed
69
engine.userDataDir = dataDir;
70
71
if (!options.disableDevtools) engine.launchArguments.push('--auto-open-devtools-for-tabs');
72
} else {
73
engine.launchArguments.push(
74
'--hide-scrollbars',
75
'--mute-audio',
76
'--blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4', // adds cursor to headless linux
77
);
78
}
79
80
if (options.disableGpu === true) {
81
engine.launchArguments.push('--disable-gpu', '--disable-software-rasterizer');
82
const idx = engine.launchArguments.indexOf('--use-gl=any');
83
if (idx >= 0) engine.launchArguments.splice(idx, 1);
84
}
85
}
86
87