webkit.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.WebKit = void 0;
  6. var _wkBrowser = require("../webkit/wkBrowser");
  7. var _path = _interopRequireDefault(require("path"));
  8. var _wkConnection = require("./wkConnection");
  9. var _browserType = require("../browserType");
  10. var _utils = require("../../utils");
  11. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12. /**
  13. * Copyright 2017 Google Inc. All rights reserved.
  14. * Modifications copyright (c) Microsoft Corporation.
  15. *
  16. * Licensed under the Apache License, Version 2.0 (the "License");
  17. * you may not use this file except in compliance with the License.
  18. * You may obtain a copy of the License at
  19. *
  20. * http://www.apache.org/licenses/LICENSE-2.0
  21. *
  22. * Unless required by applicable law or agreed to in writing, software
  23. * distributed under the License is distributed on an "AS IS" BASIS,
  24. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25. * See the License for the specific language governing permissions and
  26. * limitations under the License.
  27. */
  28. class WebKit extends _browserType.BrowserType {
  29. constructor(parent) {
  30. super(parent, 'webkit');
  31. }
  32. _connectToTransport(transport, options) {
  33. return _wkBrowser.WKBrowser.connect(this.attribution.playwright, transport, options);
  34. }
  35. _amendEnvironment(env, userDataDir, executable, browserArguments) {
  36. return {
  37. ...env,
  38. CURL_COOKIE_JAR_PATH: _path.default.join(userDataDir, 'cookiejar.db')
  39. };
  40. }
  41. _doRewriteStartupLog(error) {
  42. if (!error.logs) return error;
  43. if (error.logs.includes('cannot open display')) error.logs = '\n' + (0, _utils.wrapInASCIIBox)(_browserType.kNoXServerRunningError, 1);
  44. return error;
  45. }
  46. _attemptToGracefullyCloseBrowser(transport) {
  47. transport.send({
  48. method: 'Playwright.close',
  49. params: {},
  50. id: _wkConnection.kBrowserCloseMessageId
  51. });
  52. }
  53. _defaultArgs(options, isPersistent, userDataDir) {
  54. const {
  55. args = [],
  56. proxy,
  57. headless
  58. } = options;
  59. const userDataDirArg = args.find(arg => arg.startsWith('--user-data-dir'));
  60. if (userDataDirArg) throw this._createUserDataDirArgMisuseError('--user-data-dir');
  61. if (args.find(arg => !arg.startsWith('-'))) throw new Error('Arguments can not specify page to be opened');
  62. const webkitArguments = ['--inspector-pipe'];
  63. if (process.platform === 'win32') webkitArguments.push('--disable-accelerated-compositing');
  64. if (headless) webkitArguments.push('--headless');
  65. if (isPersistent) webkitArguments.push(`--user-data-dir=${userDataDir}`);else webkitArguments.push(`--no-startup-window`);
  66. if (proxy) {
  67. if (process.platform === 'darwin') {
  68. webkitArguments.push(`--proxy=${proxy.server}`);
  69. if (proxy.bypass) webkitArguments.push(`--proxy-bypass-list=${proxy.bypass}`);
  70. } else if (process.platform === 'linux') {
  71. webkitArguments.push(`--proxy=${proxy.server}`);
  72. if (proxy.bypass) webkitArguments.push(...proxy.bypass.split(',').map(t => `--ignore-host=${t}`));
  73. } else if (process.platform === 'win32') {
  74. // Enable socks5 hostname resolution on Windows. Workaround can be removed once fixed upstream.
  75. // See https://github.com/microsoft/playwright/issues/20451
  76. webkitArguments.push(`--curl-proxy=${proxy.server.replace(/^socks5:\/\//, 'socks5h://')}`);
  77. if (proxy.bypass) webkitArguments.push(`--curl-noproxy=${proxy.bypass}`);
  78. }
  79. }
  80. webkitArguments.push(...args);
  81. if (isPersistent) webkitArguments.push('about:blank');
  82. return webkitArguments;
  83. }
  84. }
  85. exports.WebKit = WebKit;