2019-12-19 16:53:24 -08:00
|
|
|
/**
|
|
|
|
* Copyright 2017 Google Inc. All rights reserved.
|
|
|
|
* Modifications copyright (c) Microsoft Corporation.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2020-01-07 13:58:23 -08:00
|
|
|
import * as path from 'path';
|
2020-08-22 15:46:42 -07:00
|
|
|
import { CRBrowser } from './crBrowser';
|
|
|
|
import { Env } from '../processLauncher';
|
|
|
|
import { kBrowserCloseMessageId } from './crConnection';
|
|
|
|
import { rewriteErrorMessage } from '../../utils/stackTrace';
|
2020-09-10 15:34:13 -07:00
|
|
|
import { BrowserType } from '../browserType';
|
2021-02-10 14:00:02 -08:00
|
|
|
import { ConnectionTransport, ProtocolRequest, WebSocketTransport } from '../transport';
|
2020-08-22 15:46:42 -07:00
|
|
|
import { CRDevTools } from './crDevTools';
|
2021-02-10 14:00:02 -08:00
|
|
|
import { BrowserOptions, BrowserProcess, PlaywrightOptions } from '../browser';
|
2020-08-24 06:51:51 -07:00
|
|
|
import * as types from '../types';
|
2020-11-05 14:15:25 -08:00
|
|
|
import { isDebugMode } from '../../utils/utils';
|
2021-02-10 14:00:02 -08:00
|
|
|
import { RecentLogsCollector } from '../../utils/debugLogger';
|
|
|
|
import { ProgressController } from '../progress';
|
|
|
|
import { TimeoutSettings } from '../../utils/timeoutSettings';
|
|
|
|
import { helper } from '../helper';
|
|
|
|
import { CallMetadata } from '../instrumentation';
|
2020-01-07 13:58:23 -08:00
|
|
|
|
2020-09-10 15:34:13 -07:00
|
|
|
export class Chromium extends BrowserType {
|
2020-05-19 14:55:11 -07:00
|
|
|
private _devtools: CRDevTools | undefined;
|
|
|
|
|
2021-02-08 16:02:49 -08:00
|
|
|
constructor(playwrightOptions: PlaywrightOptions) {
|
|
|
|
super('chromium', playwrightOptions);
|
2021-02-03 09:19:11 -08:00
|
|
|
|
2020-08-22 07:07:13 -07:00
|
|
|
if (isDebugMode())
|
2020-05-19 14:55:11 -07:00
|
|
|
this._devtools = this._createDevTools();
|
|
|
|
}
|
|
|
|
|
2021-02-10 14:00:02 -08:00
|
|
|
async connectOverCDP(metadata: CallMetadata, wsEndpoint: string, uiOptions: types.UIOptions, timeout?: number) {
|
|
|
|
const controller = new ProgressController(metadata, this);
|
|
|
|
controller.setLogName('browser');
|
|
|
|
const browserLogsCollector = new RecentLogsCollector();
|
|
|
|
return controller.run(async progress => {
|
|
|
|
const chromeTransport = await WebSocketTransport.connect(progress, wsEndpoint);
|
|
|
|
const browserProcess: BrowserProcess = {
|
|
|
|
close: async () => {
|
|
|
|
await chromeTransport.closeAndWait();
|
|
|
|
},
|
|
|
|
kill: async () => {
|
|
|
|
await chromeTransport.closeAndWait();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const browserOptions: BrowserOptions = {
|
|
|
|
...this._playwrightOptions,
|
|
|
|
...uiOptions,
|
|
|
|
name: 'chromium',
|
|
|
|
isChromium: true,
|
|
|
|
persistent: { noDefaultViewport: true },
|
|
|
|
browserProcess,
|
|
|
|
protocolLogger: helper.debugProtocolLogger(),
|
|
|
|
browserLogsCollector,
|
|
|
|
};
|
|
|
|
return await CRBrowser.connect(chromeTransport, browserOptions);
|
|
|
|
}, TimeoutSettings.timeout({timeout}));
|
|
|
|
}
|
|
|
|
|
2020-05-19 14:55:11 -07:00
|
|
|
private _createDevTools() {
|
2021-02-08 16:02:49 -08:00
|
|
|
return new CRDevTools(path.join(this._registry.browserDirectory('chromium'), 'devtools-preferences.json'));
|
2020-01-28 18:09:07 -08:00
|
|
|
}
|
|
|
|
|
2020-05-21 19:16:13 -07:00
|
|
|
async _connectToTransport(transport: ConnectionTransport, options: BrowserOptions): Promise<CRBrowser> {
|
2020-05-20 16:30:04 -07:00
|
|
|
let devtools = this._devtools;
|
|
|
|
if ((options as any).__testHookForDevTools) {
|
|
|
|
devtools = this._createDevTools();
|
|
|
|
await (options as any).__testHookForDevTools(devtools);
|
|
|
|
}
|
2021-02-08 16:02:49 -08:00
|
|
|
return CRBrowser.connect(transport, options, devtools);
|
2020-02-04 19:41:38 -08:00
|
|
|
}
|
|
|
|
|
2020-08-14 18:25:32 -07:00
|
|
|
_rewriteStartupError(error: Error): Error {
|
fix: re-write Chromium startup error with clear instructions (#3070)
This patch detects Chromium crash with a sandboxing error and re-writes
the error to surface information nicely.
#### Error Before:
```sh
pwuser@23592d09b3bd:~/tmp$ node a.js
(node:324) UnhandledPromiseRejectionWarning: browserType.launch: Protocol error (Browser.getVersion): Target closed.
=========================== logs ===========================
[browser] <launching> /home/pwuser/.cache/ms-playwright/chromium-790602/chrome-linux/chrome --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disab
le-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=TranslateUI,BlinkGenPropertyTrees,ImprovedCookieControls,SameSiteByDefaultCookies --disable-hang-monitor --disab
le-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --user-data-dir=/tmp/playwrig
ht_chromiumdev_profile-mjSfr2 --remote-debugging-pipe --headless --hide-scrollbars --mute-audio --no-startup-window
[browser] <launched> pid=401
[browser] [0722/170825.030020:FATAL:zygote_host_impl_linux.cc(117)] No usable sandbox! Update your kernel or see https://chromium.googlesource.com/chromium/src/+/master/docs/linux/suid_sandbox_development.md for more information on developing with the SUID sandbox. If you want to live
dangerously and need an immediate workaround, you can try using --no-sandbox.
[browser] #0 0x55ac4f8c7be9 base::debug::CollectStackTrace()
[browser] #1 0x55ac4f841c13 base::debug::StackTrace::StackTrace()
[browser] #2 0x55ac4f853680 logging::LogMessage::~LogMessage()
[browser] #3 0x55ac4df2307e content::ZygoteHostImpl::Init()
[browser] #4 0x55ac4f40dd47 content::ContentMainRunnerImpl::Initialize()
[browser] #5 0x55ac4f45c9fa service_manager::Main()
[browser] #6 0x55ac4f40c361 content::ContentMain()
[browser] #7 0x55ac4f45b5bd headless::(anonymous namespace)::RunContentMain()
[browser] #8 0x55ac4f45b2bc headless::HeadlessShellMain()
[browser] #9 0x55ac4ccc22e7 ChromeMain
[browser] #10 0x7f0f3d736b97 __libc_start_main
[browser] #11 0x55ac4ccc212a _start
[browser]
[browser] Received signal 6
[browser] #0 0x55ac4f8c7be9 base::debug::CollectStackTrace()
[browser] #1 0x55ac4f841c13 base::debug::StackTrace::StackTrace()
[browser] #2 0x55ac4f8c7785 base::debug::(anonymous namespace)::StackDumpSignalHandler()
[browser] #3 0x7f0f437b3890 (/lib/x86_64-linux-gnu/libpthread-2.27.so+0x1288f)
[browser] #4 0x7f0f3d753e97 gsignal
[browser] #5 0x7f0f3d755801 abort
[browser] #6 0x55ac4f8c66e5 base::debug::BreakDebugger()
[browser] #7 0x55ac4f853aeb logging::LogMessage::~LogMessage()
[browser] #8 0x55ac4df2307e content::ZygoteHostImpl::Init()
[browser] #9 0x55ac4f40dd47 content::ContentMainRunnerImpl::Initialize()
[browser] #10 0x55ac4f45c9fa service_manager::Main()
[browser] #11 0x55ac4f40c361 content::ContentMain()
[browser] #12 0x55ac4f45b5bd headless::(anonymous namespace)::RunContentMain()
[browser] #13 0x55ac4f45b2bc headless::HeadlessShellMain()
[browser] #14 0x55ac4ccc22e7 ChromeMain
[browser] #15 0x7f0f3d736b97 __libc_start_main
[browser] #16 0x55ac4ccc212a _start
[browser] r8: 0000000000000000 r9: 00007ffd38a863b0 r10: 0000000000000008 r11: 0000000000000246
[browser] r12: 00007ffd38a87680 r13: 00007ffd38a86610 r14: 00007ffd38a87690 r15: aaaaaaaaaaaaaaaa
[browser] di: 0000000000000002 si: 00007ffd38a863b0 bp: 00007ffd38a86600 bx: 00007ffd38a86e44
[browser] dx: 0000000000000000 ax: 0000000000000000 cx: 00007f0f3d753e97 sp: 00007ffd38a863b0
[browser] ip: 00007f0f3d753e97 efl: 0000000000000246 cgf: 002b000000000033 erf: 0000000000000000
[browser] trp: 0000000000000000 msk: 0000000000000000 cr2: 0000000000000000
[browser] [end of stack trace]
[browser] Calling _exit(1). Core file will not be generated.
============================================================
Note: use DEBUG=pw:api environment variable and rerun to capture Playwright logs.Error
at /home/pwuser/tmp/node_modules/playwright/lib/chromium/crConnection.js:131:63
at new Promise (<anonymous>)
at CRSession.send (/home/pwuser/tmp/node_modules/playwright/lib/chromium/crConnection.js:130:16)
at CRSession.send (/home/pwuser/tmp/node_modules/playwright/lib/helper.js:78:31)
at Function.connect (/home/pwuser/tmp/node_modules/playwright/lib/chromium/crBrowser.js:54:39)
at Chromium._connectToTransport (/home/pwuser/tmp/node_modules/playwright/lib/server/chromium.js:52:38)
at Chromium._innerLaunch (/home/pwuser/tmp/node_modules/playwright/lib/server/browserType.js:87:36)
at async ProgressController.run (/home/pwuser/tmp/node_modules/playwright/lib/progress.js:75:28)
at async Chromium.launch (/home/pwuser/tmp/node_modules/playwright/lib/server/browserType.js:60:25)
at async /home/pwuser/tmp/a.js:4:19
(node:324) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise reject
ion, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:324) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
```
#### Error After:
```sh
pwuser@23592d09b3bd:~/tmp$ node a.js
(node:222) UnhandledPromiseRejectionWarning: browserType.launch: Chromium sandboxing failed!
================================
To workaround sandboxing issues, do either of the following:
- (preferred): Configure environment to support sandboxing: https://github.com/microsoft/playwright/blob/master/docs/troubleshooting.md
- (alternative): Launch Chromium without sandbox using 'chromiumSandbox: false' option
================================
Error
at /home/pwuser/tmp/node_modules/playwright/lib/chromium/crConnection.js:131:63
at new Promise (<anonymous>)
at CRSession.send (/home/pwuser/tmp/node_modules/playwright/lib/chromium/crConnection.js:130:16)
at CRSession.send (/home/pwuser/tmp/node_modules/playwright/lib/helper.js:78:31)
at Function.connect (/home/pwuser/tmp/node_modules/playwright/lib/chromium/crBrowser.js:54:27)
at Chromium._connectToTransport (/home/pwuser/tmp/node_modules/playwright/lib/server/chromium.js:53:38)
at Chromium._innerLaunch (/home/pwuser/tmp/node_modules/playwright/lib/server/browserType.js:89:36)
at async ProgressController.run (/home/pwuser/tmp/node_modules/playwright/lib/progress.js:75:28)
at async Chromium.launch (/home/pwuser/tmp/node_modules/playwright/lib/server/browserType.js:61:25)
at async /home/pwuser/tmp/a.js:4:19
(node:222) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise reject
ion, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:222) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
```
References #2745
2020-07-22 10:57:58 -07:00
|
|
|
// These error messages are taken from Chromium source code as of July, 2020:
|
|
|
|
// https://github.com/chromium/chromium/blob/70565f67e79f79e17663ad1337dc6e63ee207ce9/content/browser/zygote_host/zygote_host_impl_linux.cc
|
|
|
|
if (!error.message.includes('crbug.com/357670') && !error.message.includes('No usable sandbox!') && !error.message.includes('crbug.com/638180'))
|
|
|
|
return error;
|
|
|
|
return rewriteErrorMessage(error, [
|
2020-08-14 18:25:32 -07:00
|
|
|
`Chromium sandboxing failed!`,
|
fix: re-write Chromium startup error with clear instructions (#3070)
This patch detects Chromium crash with a sandboxing error and re-writes
the error to surface information nicely.
#### Error Before:
```sh
pwuser@23592d09b3bd:~/tmp$ node a.js
(node:324) UnhandledPromiseRejectionWarning: browserType.launch: Protocol error (Browser.getVersion): Target closed.
=========================== logs ===========================
[browser] <launching> /home/pwuser/.cache/ms-playwright/chromium-790602/chrome-linux/chrome --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disab
le-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=TranslateUI,BlinkGenPropertyTrees,ImprovedCookieControls,SameSiteByDefaultCookies --disable-hang-monitor --disab
le-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --user-data-dir=/tmp/playwrig
ht_chromiumdev_profile-mjSfr2 --remote-debugging-pipe --headless --hide-scrollbars --mute-audio --no-startup-window
[browser] <launched> pid=401
[browser] [0722/170825.030020:FATAL:zygote_host_impl_linux.cc(117)] No usable sandbox! Update your kernel or see https://chromium.googlesource.com/chromium/src/+/master/docs/linux/suid_sandbox_development.md for more information on developing with the SUID sandbox. If you want to live
dangerously and need an immediate workaround, you can try using --no-sandbox.
[browser] #0 0x55ac4f8c7be9 base::debug::CollectStackTrace()
[browser] #1 0x55ac4f841c13 base::debug::StackTrace::StackTrace()
[browser] #2 0x55ac4f853680 logging::LogMessage::~LogMessage()
[browser] #3 0x55ac4df2307e content::ZygoteHostImpl::Init()
[browser] #4 0x55ac4f40dd47 content::ContentMainRunnerImpl::Initialize()
[browser] #5 0x55ac4f45c9fa service_manager::Main()
[browser] #6 0x55ac4f40c361 content::ContentMain()
[browser] #7 0x55ac4f45b5bd headless::(anonymous namespace)::RunContentMain()
[browser] #8 0x55ac4f45b2bc headless::HeadlessShellMain()
[browser] #9 0x55ac4ccc22e7 ChromeMain
[browser] #10 0x7f0f3d736b97 __libc_start_main
[browser] #11 0x55ac4ccc212a _start
[browser]
[browser] Received signal 6
[browser] #0 0x55ac4f8c7be9 base::debug::CollectStackTrace()
[browser] #1 0x55ac4f841c13 base::debug::StackTrace::StackTrace()
[browser] #2 0x55ac4f8c7785 base::debug::(anonymous namespace)::StackDumpSignalHandler()
[browser] #3 0x7f0f437b3890 (/lib/x86_64-linux-gnu/libpthread-2.27.so+0x1288f)
[browser] #4 0x7f0f3d753e97 gsignal
[browser] #5 0x7f0f3d755801 abort
[browser] #6 0x55ac4f8c66e5 base::debug::BreakDebugger()
[browser] #7 0x55ac4f853aeb logging::LogMessage::~LogMessage()
[browser] #8 0x55ac4df2307e content::ZygoteHostImpl::Init()
[browser] #9 0x55ac4f40dd47 content::ContentMainRunnerImpl::Initialize()
[browser] #10 0x55ac4f45c9fa service_manager::Main()
[browser] #11 0x55ac4f40c361 content::ContentMain()
[browser] #12 0x55ac4f45b5bd headless::(anonymous namespace)::RunContentMain()
[browser] #13 0x55ac4f45b2bc headless::HeadlessShellMain()
[browser] #14 0x55ac4ccc22e7 ChromeMain
[browser] #15 0x7f0f3d736b97 __libc_start_main
[browser] #16 0x55ac4ccc212a _start
[browser] r8: 0000000000000000 r9: 00007ffd38a863b0 r10: 0000000000000008 r11: 0000000000000246
[browser] r12: 00007ffd38a87680 r13: 00007ffd38a86610 r14: 00007ffd38a87690 r15: aaaaaaaaaaaaaaaa
[browser] di: 0000000000000002 si: 00007ffd38a863b0 bp: 00007ffd38a86600 bx: 00007ffd38a86e44
[browser] dx: 0000000000000000 ax: 0000000000000000 cx: 00007f0f3d753e97 sp: 00007ffd38a863b0
[browser] ip: 00007f0f3d753e97 efl: 0000000000000246 cgf: 002b000000000033 erf: 0000000000000000
[browser] trp: 0000000000000000 msk: 0000000000000000 cr2: 0000000000000000
[browser] [end of stack trace]
[browser] Calling _exit(1). Core file will not be generated.
============================================================
Note: use DEBUG=pw:api environment variable and rerun to capture Playwright logs.Error
at /home/pwuser/tmp/node_modules/playwright/lib/chromium/crConnection.js:131:63
at new Promise (<anonymous>)
at CRSession.send (/home/pwuser/tmp/node_modules/playwright/lib/chromium/crConnection.js:130:16)
at CRSession.send (/home/pwuser/tmp/node_modules/playwright/lib/helper.js:78:31)
at Function.connect (/home/pwuser/tmp/node_modules/playwright/lib/chromium/crBrowser.js:54:39)
at Chromium._connectToTransport (/home/pwuser/tmp/node_modules/playwright/lib/server/chromium.js:52:38)
at Chromium._innerLaunch (/home/pwuser/tmp/node_modules/playwright/lib/server/browserType.js:87:36)
at async ProgressController.run (/home/pwuser/tmp/node_modules/playwright/lib/progress.js:75:28)
at async Chromium.launch (/home/pwuser/tmp/node_modules/playwright/lib/server/browserType.js:60:25)
at async /home/pwuser/tmp/a.js:4:19
(node:324) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise reject
ion, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:324) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
```
#### Error After:
```sh
pwuser@23592d09b3bd:~/tmp$ node a.js
(node:222) UnhandledPromiseRejectionWarning: browserType.launch: Chromium sandboxing failed!
================================
To workaround sandboxing issues, do either of the following:
- (preferred): Configure environment to support sandboxing: https://github.com/microsoft/playwright/blob/master/docs/troubleshooting.md
- (alternative): Launch Chromium without sandbox using 'chromiumSandbox: false' option
================================
Error
at /home/pwuser/tmp/node_modules/playwright/lib/chromium/crConnection.js:131:63
at new Promise (<anonymous>)
at CRSession.send (/home/pwuser/tmp/node_modules/playwright/lib/chromium/crConnection.js:130:16)
at CRSession.send (/home/pwuser/tmp/node_modules/playwright/lib/helper.js:78:31)
at Function.connect (/home/pwuser/tmp/node_modules/playwright/lib/chromium/crBrowser.js:54:27)
at Chromium._connectToTransport (/home/pwuser/tmp/node_modules/playwright/lib/server/chromium.js:53:38)
at Chromium._innerLaunch (/home/pwuser/tmp/node_modules/playwright/lib/server/browserType.js:89:36)
at async ProgressController.run (/home/pwuser/tmp/node_modules/playwright/lib/progress.js:75:28)
at async Chromium.launch (/home/pwuser/tmp/node_modules/playwright/lib/server/browserType.js:61:25)
at async /home/pwuser/tmp/a.js:4:19
(node:222) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise reject
ion, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:222) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
```
References #2745
2020-07-22 10:57:58 -07:00
|
|
|
`================================`,
|
|
|
|
`To workaround sandboxing issues, do either of the following:`,
|
|
|
|
` - (preferred): Configure environment to support sandboxing: https://github.com/microsoft/playwright/blob/master/docs/troubleshooting.md`,
|
|
|
|
` - (alternative): Launch Chromium without sandbox using 'chromiumSandbox: false' option`,
|
|
|
|
`================================`,
|
|
|
|
``,
|
|
|
|
].join('\n'));
|
|
|
|
}
|
|
|
|
|
2020-05-22 07:03:42 -07:00
|
|
|
_amendEnvironment(env: Env, userDataDir: string, executable: string, browserArguments: string[]): Env {
|
|
|
|
return env;
|
|
|
|
}
|
2020-05-14 13:22:33 -07:00
|
|
|
|
2020-05-22 07:03:42 -07:00
|
|
|
_attemptToGracefullyCloseBrowser(transport: ConnectionTransport): void {
|
|
|
|
const message: ProtocolRequest = { method: 'Browser.close', id: kBrowserCloseMessageId, params: {} };
|
|
|
|
transport.send(message);
|
|
|
|
}
|
2020-01-07 13:58:23 -08:00
|
|
|
|
2020-08-18 09:37:40 -07:00
|
|
|
_defaultArgs(options: types.LaunchOptions, isPersistent: boolean, userDataDir: string): string[] {
|
2020-06-05 13:50:15 -07:00
|
|
|
const { args = [], proxy } = options;
|
2020-02-05 16:36:36 -08:00
|
|
|
const userDataDirArg = args.find(arg => arg.startsWith('--user-data-dir'));
|
|
|
|
if (userDataDirArg)
|
|
|
|
throw new Error('Pass userDataDir parameter instead of specifying --user-data-dir argument');
|
2020-04-18 19:06:42 -07:00
|
|
|
if (args.find(arg => arg.startsWith('--remote-debugging-pipe')))
|
2020-02-05 16:36:36 -08:00
|
|
|
throw new Error('Playwright manages remote debugging connection itself.');
|
2020-05-10 15:23:53 -07:00
|
|
|
if (args.find(arg => !arg.startsWith('-')))
|
2020-02-27 14:09:24 -08:00
|
|
|
throw new Error('Arguments can not specify page to be opened');
|
2020-01-07 13:58:23 -08:00
|
|
|
const chromeArguments = [...DEFAULT_ARGS];
|
2020-02-05 16:36:36 -08:00
|
|
|
chromeArguments.push(`--user-data-dir=${userDataDir}`);
|
2020-11-05 14:15:25 -08:00
|
|
|
chromeArguments.push('--remote-debugging-pipe');
|
2020-06-10 20:48:54 -07:00
|
|
|
if (options.devtools)
|
2020-01-07 13:58:23 -08:00
|
|
|
chromeArguments.push('--auto-open-devtools-for-tabs');
|
2020-06-10 20:48:54 -07:00
|
|
|
if (options.headless) {
|
2020-01-07 13:58:23 -08:00
|
|
|
chromeArguments.push(
|
|
|
|
'--headless',
|
|
|
|
'--hide-scrollbars',
|
2020-09-21 08:20:05 -07:00
|
|
|
'--mute-audio',
|
|
|
|
'--blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4',
|
2020-01-07 13:58:23 -08:00
|
|
|
);
|
|
|
|
}
|
2020-10-09 11:28:22 -07:00
|
|
|
if (options.chromiumSandbox !== true)
|
2020-07-21 13:49:09 -07:00
|
|
|
chromeArguments.push('--no-sandbox');
|
2020-06-05 13:50:15 -07:00
|
|
|
if (proxy) {
|
|
|
|
const proxyURL = new URL(proxy.server);
|
|
|
|
const isSocks = proxyURL.protocol === 'socks5:';
|
|
|
|
// https://www.chromium.org/developers/design-documents/network-settings
|
|
|
|
if (isSocks) {
|
|
|
|
// https://www.chromium.org/developers/design-documents/network-stack/socks-proxy
|
|
|
|
chromeArguments.push(`--host-resolver-rules="MAP * ~NOTFOUND , EXCLUDE ${proxyURL.hostname}"`);
|
|
|
|
}
|
|
|
|
chromeArguments.push(`--proxy-server=${proxy.server}`);
|
|
|
|
if (proxy.bypass) {
|
|
|
|
const patterns = proxy.bypass.split(',').map(t => t.trim()).map(t => t.startsWith('.') ? '*' + t : t);
|
|
|
|
chromeArguments.push(`--proxy-bypass-list=${patterns.join(';')}`);
|
|
|
|
}
|
|
|
|
}
|
2020-02-05 16:36:36 -08:00
|
|
|
chromeArguments.push(...args);
|
2020-05-22 16:06:00 -07:00
|
|
|
if (isPersistent)
|
2020-05-10 15:23:53 -07:00
|
|
|
chromeArguments.push('about:blank');
|
|
|
|
else
|
2020-03-05 14:46:12 -08:00
|
|
|
chromeArguments.push('--no-startup-window');
|
2020-01-07 13:58:23 -08:00
|
|
|
return chromeArguments;
|
2019-12-19 16:53:24 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-08 16:02:23 -08:00
|
|
|
const DEFAULT_ARGS = [
|
2020-01-07 13:58:23 -08:00
|
|
|
'--disable-background-networking',
|
|
|
|
'--enable-features=NetworkService,NetworkServiceInProcess',
|
|
|
|
'--disable-background-timer-throttling',
|
|
|
|
'--disable-backgrounding-occluded-windows',
|
|
|
|
'--disable-breakpad',
|
|
|
|
'--disable-client-side-phishing-detection',
|
|
|
|
'--disable-component-extensions-with-background-pages',
|
|
|
|
'--disable-default-apps',
|
|
|
|
'--disable-dev-shm-usage',
|
|
|
|
'--disable-extensions',
|
|
|
|
// BlinkGenPropertyTrees disabled due to crbug.com/937609
|
2020-08-19 15:58:13 -07:00
|
|
|
'--disable-features=TranslateUI,BlinkGenPropertyTrees,ImprovedCookieControls,SameSiteByDefaultCookies,LazyFrameLoading',
|
2020-01-07 13:58:23 -08:00
|
|
|
'--disable-hang-monitor',
|
|
|
|
'--disable-ipc-flooding-protection',
|
|
|
|
'--disable-popup-blocking',
|
|
|
|
'--disable-prompt-on-repost',
|
|
|
|
'--disable-renderer-backgrounding',
|
|
|
|
'--disable-sync',
|
|
|
|
'--force-color-profile=srgb',
|
|
|
|
'--metrics-recording-only',
|
|
|
|
'--no-first-run',
|
|
|
|
'--enable-automation',
|
|
|
|
'--password-store=basic',
|
|
|
|
'--use-mock-keychain',
|
|
|
|
];
|