patchright-core 1.50.1 → 1.51.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (242) hide show
  1. package/ThirdPartyNotices.txt +1 -43
  2. package/browsers.json +22 -10
  3. package/index.js +0 -1
  4. package/lib/androidServerImpl.js +4 -4
  5. package/lib/browserServerImpl.js +18 -9
  6. package/lib/cli/driver.js +6 -6
  7. package/lib/cli/program.js +9 -9
  8. package/lib/cli/programWithTestStub.js +2 -1
  9. package/lib/client/android.js +37 -58
  10. package/lib/client/artifact.js +4 -7
  11. package/lib/client/browser.js +10 -15
  12. package/lib/client/browserContext.js +77 -73
  13. package/lib/client/browserType.js +30 -64
  14. package/lib/client/channelOwner.js +23 -20
  15. package/lib/client/clientHelper.js +5 -7
  16. package/lib/client/clientStackTrace.js +65 -0
  17. package/lib/client/connection.js +46 -39
  18. package/lib/client/consoleMessage.js +4 -7
  19. package/lib/client/electron.js +10 -10
  20. package/lib/client/elementHandle.js +32 -33
  21. package/lib/client/errors.js +2 -2
  22. package/lib/client/eventEmitter.js +5 -8
  23. package/lib/client/fetch.js +60 -61
  24. package/lib/client/fileUtils.js +31 -0
  25. package/lib/client/frame.js +30 -29
  26. package/lib/client/harRouter.js +7 -9
  27. package/lib/client/jsHandle.js +3 -4
  28. package/lib/client/localUtils.js +24 -0
  29. package/lib/client/locator.js +37 -18
  30. package/lib/client/network.js +40 -40
  31. package/lib/client/page.js +59 -55
  32. package/lib/client/platform.js +71 -0
  33. package/lib/client/playwright.js +21 -1
  34. package/lib/client/selectors.js +8 -2
  35. package/lib/client/stream.js +2 -21
  36. package/lib/client/timeoutSettings.js +65 -0
  37. package/lib/client/tracing.js +10 -7
  38. package/lib/client/video.js +2 -2
  39. package/lib/client/waiter.js +5 -6
  40. package/lib/client/webSocket.js +106 -0
  41. package/lib/client/worker.js +12 -10
  42. package/lib/client/writableStream.js +2 -21
  43. package/lib/generated/consoleApiSource.js +1 -1
  44. package/lib/generated/injectedScriptSource.js +1 -1
  45. package/lib/inProcessFactory.js +6 -3
  46. package/lib/outofprocess.js +12 -8
  47. package/lib/protocol/validator.js +64 -13
  48. package/lib/protocol/validatorPrimitives.js +1 -2
  49. package/lib/remote/playwrightConnection.js +18 -10
  50. package/lib/remote/playwrightServer.js +20 -7
  51. package/lib/server/android/android.js +17 -14
  52. package/lib/server/android/backendAdb.js +14 -14
  53. package/lib/server/artifact.js +3 -3
  54. package/lib/server/bidi/bidiBrowser.js +2 -2
  55. package/lib/server/bidi/bidiChromium.js +4 -3
  56. package/lib/server/bidi/bidiConnection.js +1 -1
  57. package/lib/server/bidi/bidiExecutionContext.js +70 -40
  58. package/lib/server/bidi/bidiFirefox.js +4 -3
  59. package/lib/server/bidi/bidiInput.js +5 -8
  60. package/lib/server/bidi/bidiNetworkManager.js +3 -3
  61. package/lib/server/bidi/bidiOverCdp.js +2 -2
  62. package/lib/server/bidi/bidiPage.js +30 -46
  63. package/lib/server/bidi/third_party/firefoxPrefs.js +19 -3
  64. package/lib/server/browser.js +2 -2
  65. package/lib/server/browserContext.js +37 -40
  66. package/lib/server/browserType.js +18 -17
  67. package/lib/{utils/sequence.js → server/callLog.js} +18 -3
  68. package/lib/server/chromium/chromium.js +14 -14
  69. package/lib/server/chromium/chromiumSwitches.js +32 -1
  70. package/lib/server/chromium/crBrowser.js +15 -14
  71. package/lib/server/chromium/crConnection.js +2 -2
  72. package/lib/server/chromium/crCoverage.js +1 -1
  73. package/lib/server/chromium/crDevTools.js +1 -1
  74. package/lib/server/chromium/crDragDrop.js +1 -1
  75. package/lib/server/chromium/crExecutionContext.js +25 -17
  76. package/lib/server/chromium/crInput.js +2 -2
  77. package/lib/server/chromium/crNetworkManager.js +73 -26
  78. package/lib/server/chromium/crPage.js +22 -23
  79. package/lib/server/chromium/crPdf.js +1 -1
  80. package/lib/server/chromium/crProtocolHelper.js +3 -3
  81. package/lib/server/chromium/crServiceWorker.js +2 -2
  82. package/lib/server/chromium/videoRecorder.js +2 -2
  83. package/lib/server/clock.js +1 -1
  84. package/lib/server/codegen/javascript.js +1 -1
  85. package/lib/server/codegen/languages.js +2 -2
  86. package/lib/server/debugController.js +3 -3
  87. package/lib/server/deviceDescriptors.js +1 -1
  88. package/lib/server/deviceDescriptorsSource.json +131 -131
  89. package/lib/server/dispatchers/androidDispatcher.js +1 -1
  90. package/lib/server/dispatchers/artifactDispatcher.js +3 -3
  91. package/lib/server/dispatchers/browserContextDispatcher.js +19 -19
  92. package/lib/server/dispatchers/browserTypeDispatcher.js +1 -1
  93. package/lib/server/dispatchers/cdpSessionDispatcher.js +1 -1
  94. package/lib/server/dispatchers/dispatcher.js +27 -25
  95. package/lib/server/dispatchers/electronDispatcher.js +3 -3
  96. package/lib/server/dispatchers/elementHandlerDispatcher.js +7 -2
  97. package/lib/server/dispatchers/frameDispatcher.js +4 -4
  98. package/lib/server/dispatchers/jsHandleDispatcher.js +2 -2
  99. package/lib/server/dispatchers/jsonPipeDispatcher.js +2 -2
  100. package/lib/server/dispatchers/localUtilsDispatcher.js +25 -298
  101. package/lib/server/dispatchers/networkDispatchers.js +3 -3
  102. package/lib/server/dispatchers/pageDispatcher.js +11 -9
  103. package/lib/server/dispatchers/playwrightDispatcher.js +5 -5
  104. package/lib/server/dispatchers/streamDispatcher.js +4 -3
  105. package/lib/server/dispatchers/webSocketRouteDispatcher.js +8 -7
  106. package/lib/server/dispatchers/writableStreamDispatcher.js +5 -6
  107. package/lib/server/dom.js +18 -12
  108. package/lib/server/download.js +1 -1
  109. package/lib/server/electron/electron.js +17 -16
  110. package/lib/server/errors.js +1 -1
  111. package/lib/server/fetch.js +36 -25
  112. package/lib/server/fileUploadUtils.js +7 -4
  113. package/lib/server/firefox/ffBrowser.js +8 -2
  114. package/lib/server/firefox/ffConnection.js +1 -1
  115. package/lib/server/firefox/ffExecutionContext.js +25 -17
  116. package/lib/server/firefox/ffNetworkManager.js +2 -2
  117. package/lib/server/firefox/ffPage.js +15 -21
  118. package/lib/server/firefox/firefox.js +7 -9
  119. package/lib/server/frameSelectors.js +1 -1
  120. package/lib/server/frames.js +366 -209
  121. package/lib/server/har/harRecorder.js +4 -4
  122. package/lib/server/har/harTracer.js +7 -8
  123. package/lib/server/harBackend.js +157 -0
  124. package/lib/server/helper.js +2 -2
  125. package/lib/server/index.js +1 -8
  126. package/lib/server/input.js +1 -1
  127. package/lib/server/instrumentation.js +2 -2
  128. package/lib/server/isomorphic/utilityScriptSerializers.js +3 -0
  129. package/lib/server/javascript.js +46 -33
  130. package/lib/server/launchApp.js +2 -2
  131. package/lib/server/localUtils.js +203 -0
  132. package/lib/server/network.js +3 -3
  133. package/lib/server/page.js +41 -22
  134. package/lib/server/pipeTransport.js +1 -1
  135. package/lib/server/playwright.js +5 -5
  136. package/lib/server/progress.js +1 -1
  137. package/lib/server/protocolError.js +1 -1
  138. package/lib/server/recorder/contextRecorder.js +3 -3
  139. package/lib/server/recorder/recorderApp.js +18 -12
  140. package/lib/server/recorder/recorderCollection.js +3 -3
  141. package/lib/server/recorder/throttledFile.js +3 -4
  142. package/lib/server/recorder.js +7 -5
  143. package/lib/server/registry/browserFetcher.js +9 -7
  144. package/lib/server/registry/dependencies.js +15 -15
  145. package/lib/server/registry/index.js +38 -44
  146. package/lib/server/registry/oopDownloadBrowserMain.js +3 -3
  147. package/lib/server/screenshotter.js +1 -1
  148. package/lib/server/selectors.js +3 -3
  149. package/lib/server/socksClientCertificatesInterceptor.js +8 -8
  150. package/lib/server/socksInterceptor.js +8 -5
  151. package/lib/server/storageScript.js +160 -0
  152. package/lib/{common → server}/timeoutSettings.js +6 -5
  153. package/lib/server/trace/recorder/snapshotter.js +9 -8
  154. package/lib/server/trace/recorder/tracing.js +40 -31
  155. package/lib/server/trace/test/inMemorySnapshotter.js +4 -4
  156. package/lib/server/trace/viewer/traceViewer.js +13 -5
  157. package/lib/server/transport.js +2 -2
  158. package/lib/{utils → server/utils}/comparators.js +4 -4
  159. package/lib/{utils → server/utils}/crypto.js +4 -4
  160. package/lib/{utils → server/utils}/debug.js +4 -12
  161. package/lib/{utils → server/utils}/debugLogger.js +2 -2
  162. package/lib/{utils → server/utils}/env.js +4 -0
  163. package/lib/{utils → server/utils}/expectUtils.js +1 -1
  164. package/lib/{utils → server/utils}/fileUtils.js +4 -5
  165. package/lib/{utils/happy-eyeballs.js → server/utils/happyEyeballs.js} +22 -24
  166. package/lib/{utils → server/utils}/hostPlatform.js +1 -1
  167. package/lib/{utils → server/utils}/httpServer.js +8 -8
  168. package/lib/{utils → server/utils}/linuxUtils.js +3 -23
  169. package/lib/{utils → server/utils}/network.js +4 -4
  170. package/lib/server/utils/nodePlatform.js +140 -0
  171. package/lib/{protocol/transport.js → server/utils/pipeTransport.js} +2 -2
  172. package/lib/{utils → server/utils}/processLauncher.js +5 -5
  173. package/lib/{utils → server/utils}/profiler.js +5 -6
  174. package/lib/{common → server/utils}/socksProxy.js +10 -9
  175. package/lib/{utils → server/utils}/userAgent.js +2 -16
  176. package/lib/{utils → server/utils}/wsServer.js +3 -3
  177. package/lib/{utils → server/utils}/zipFile.js +1 -1
  178. package/lib/{utils → server/utils}/zones.js +9 -24
  179. package/lib/server/webkit/webkit.js +4 -4
  180. package/lib/server/webkit/wkBrowser.js +4 -4
  181. package/lib/server/webkit/wkConnection.js +1 -1
  182. package/lib/server/webkit/wkExecutionContext.js +25 -17
  183. package/lib/server/webkit/wkInput.js +2 -2
  184. package/lib/server/webkit/wkInterceptableRequest.js +2 -2
  185. package/lib/server/webkit/wkPage.js +41 -40
  186. package/lib/server/webkit/wkProvisionalPage.js +1 -1
  187. package/lib/server/webkit/wkWorkers.js +2 -2
  188. package/lib/utils/isomorphic/ariaSnapshot.js +2 -1
  189. package/lib/utils/isomorphic/assert.js +25 -0
  190. package/lib/utils/isomorphic/colors.js +65 -0
  191. package/lib/utils/isomorphic/cssParser.js +1 -1
  192. package/lib/utils/isomorphic/locatorGenerators.js +13 -1
  193. package/lib/utils/isomorphic/locatorParser.js +2 -2
  194. package/lib/utils/{manualPromise.js → isomorphic/manualPromise.js} +3 -5
  195. package/lib/utils/isomorphic/mimeType.js +11 -3
  196. package/lib/utils/{multimap.js → isomorphic/multimap.js} +1 -3
  197. package/lib/utils/{rtti.js → isomorphic/rtti.js} +2 -5
  198. package/lib/utils/isomorphic/stackTrace.js +169 -0
  199. package/lib/utils/isomorphic/stringUtils.js +1 -1
  200. package/lib/utils/{time.js → isomorphic/time.js} +1 -13
  201. package/lib/utils/{timeoutRunner.js → isomorphic/timeoutRunner.js} +4 -4
  202. package/lib/utils/isomorphic/traceUtils.js +23 -0
  203. package/lib/{utils/index.js → utils.js} +200 -121
  204. package/lib/utilsBundle.js +1 -25
  205. package/lib/utilsBundleImpl/index.js +114 -116
  206. package/lib/vite/htmlReport/index.html +20 -20
  207. package/lib/vite/recorder/assets/codeMirrorModule-B9YMkrwa.js +24 -0
  208. package/lib/vite/recorder/assets/index-ELPgmkwA.js +184 -0
  209. package/lib/vite/recorder/index.html +1 -1
  210. package/lib/vite/traceViewer/assets/codeMirrorModule-DpJ-EmBQ.js +24 -0
  211. package/lib/vite/traceViewer/assets/defaultSettingsView-DTenqiGw.js +259 -0
  212. package/lib/vite/traceViewer/assets/{xtermModule-c-SNdYZy.js → xtermModule-BoAIEibi.js} +7 -7
  213. package/lib/vite/traceViewer/defaultSettingsView.5fN5lw10.css +1 -0
  214. package/lib/vite/traceViewer/index.CUq7VgrV.js +2 -0
  215. package/lib/vite/traceViewer/index.html +3 -3
  216. package/lib/vite/traceViewer/sw.bundle.js +3 -3
  217. package/lib/vite/traceViewer/uiMode.CHJSAD7F.js +5 -0
  218. package/lib/vite/traceViewer/uiMode.html +3 -3
  219. package/lib/zipBundleImpl.js +4 -4
  220. package/package.json +7 -7
  221. package/types/protocol.d.ts +123 -99
  222. package/types/types.d.ts +91 -37
  223. package/lib/utils/stackTrace.js +0 -134
  224. package/lib/utils/traceUtils.js +0 -44
  225. package/lib/vite/recorder/assets/codeMirrorModule-CNAqJrkA.js +0 -24
  226. package/lib/vite/recorder/assets/index-DGS0JLxS.js +0 -184
  227. package/lib/vite/traceViewer/assets/codeMirrorModule-D55P_UuL.js +0 -24
  228. package/lib/vite/traceViewer/assets/defaultSettingsView-B-uNoFsX.js +0 -243
  229. package/lib/vite/traceViewer/defaultSettingsView.2xeEXCXv.css +0 -1
  230. package/lib/vite/traceViewer/index.BfvuujqP.js +0 -2
  231. package/lib/vite/traceViewer/uiMode.CStJu6jo.js +0 -5
  232. /package/lib/{utils → server/utils}/ascii.js +0 -0
  233. /package/lib/{utils → server/utils}/eventsHelper.js +0 -0
  234. /package/lib/{image_tools → server/utils/image_tools}/colorUtils.js +0 -0
  235. /package/lib/{image_tools → server/utils/image_tools}/compare.js +0 -0
  236. /package/lib/{image_tools → server/utils/image_tools}/imageChannel.js +0 -0
  237. /package/lib/{image_tools → server/utils/image_tools}/stats.js +0 -0
  238. /package/lib/{utils → server/utils}/spawnAsync.js +0 -0
  239. /package/lib/{utils → server/utils}/task.js +0 -0
  240. /package/lib/utils/{headers.js → isomorphic/headers.js} +0 -0
  241. /package/lib/utils/{semaphore.js → isomorphic/semaphore.js} +0 -0
  242. /package/lib/{common → utils/isomorphic}/types.js +0 -0
@@ -6,9 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.addSourceUrlToScript = addSourceUrlToScript;
7
7
  exports.envObjectToArray = envObjectToArray;
8
8
  exports.evaluationScript = evaluationScript;
9
- var _fs = _interopRequireDefault(require("fs"));
10
- var _utils = require("../utils");
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ var _rtti = require("../utils/isomorphic/rtti");
12
10
  /**
13
11
  * Copyright 2017 Google Inc. All rights reserved.
14
12
  * Modifications copyright (c) Microsoft Corporation.
@@ -36,22 +34,22 @@ function envObjectToArray(env) {
36
34
  }
37
35
  return result;
38
36
  }
39
- async function evaluationScript(fun, arg, addSourceUrl = true) {
37
+ async function evaluationScript(platform, fun, arg, addSourceUrl = true) {
40
38
  if (typeof fun === 'function') {
41
39
  const source = fun.toString();
42
40
  const argString = Object.is(arg, undefined) ? 'undefined' : JSON.stringify(arg);
43
41
  return `(${source})(${argString})`;
44
42
  }
45
43
  if (arg !== undefined) throw new Error('Cannot evaluate a string with arguments');
46
- if ((0, _utils.isString)(fun)) return fun;
44
+ if ((0, _rtti.isString)(fun)) return fun;
47
45
  if (fun.content !== undefined) return fun.content;
48
46
  if (fun.path !== undefined) {
49
- let source = await _fs.default.promises.readFile(fun.path, 'utf8');
47
+ let source = await platform.fs().promises.readFile(fun.path, 'utf8');
50
48
  if (addSourceUrl) source = addSourceUrlToScript(source, fun.path);
51
49
  return source;
52
50
  }
53
51
  throw new Error('Either path or content property must be present');
54
52
  }
55
53
  function addSourceUrlToScript(source, path) {
56
- return script;
54
+ return source;
57
55
  }
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.captureLibraryStackTrace = captureLibraryStackTrace;
7
+ var _stackTrace = require("../utils/isomorphic/stackTrace");
8
+ /**
9
+ * Copyright (c) Microsoft Corporation.
10
+ *
11
+ * Licensed under the Apache License, Version 2.0 (the "License");
12
+ * you may not use this file except in compliance with the License.
13
+ * You may obtain a copy of the License at
14
+ *
15
+ * http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software
18
+ * distributed under the License is distributed on an "AS IS" BASIS,
19
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ * See the License for the specific language governing permissions and
21
+ * limitations under the License.
22
+ */
23
+
24
+ function captureLibraryStackTrace(platform) {
25
+ const stack = (0, _stackTrace.captureRawStack)();
26
+ let parsedFrames = stack.map(line => {
27
+ const frame = (0, _stackTrace.parseStackFrame)(line, platform.pathSeparator, platform.showInternalStackFrames());
28
+ if (!frame || !frame.file) return null;
29
+ const isPlaywrightLibrary = !!platform.coreDir && frame.file.startsWith(platform.coreDir);
30
+ const parsed = {
31
+ frame,
32
+ frameText: line,
33
+ isPlaywrightLibrary
34
+ };
35
+ return parsed;
36
+ }).filter(Boolean);
37
+ let apiName = '';
38
+
39
+ // Deepest transition between non-client code calling into client
40
+ // code is the api entry.
41
+ for (let i = 0; i < parsedFrames.length - 1; i++) {
42
+ const parsedFrame = parsedFrames[i];
43
+ if (parsedFrame.isPlaywrightLibrary && !parsedFrames[i + 1].isPlaywrightLibrary) {
44
+ apiName = apiName || normalizeAPIName(parsedFrame.frame.function);
45
+ break;
46
+ }
47
+ }
48
+ function normalizeAPIName(name) {
49
+ if (!name) return '';
50
+ const match = name.match(/(API|JS|CDP|[A-Z])(.*)/);
51
+ if (!match) return name;
52
+ return match[1].toLowerCase() + match[2];
53
+ }
54
+
55
+ // This is for the inspector so that it did not include the test runner stack frames.
56
+ const filterPrefixes = platform.boxedStackPrefixes();
57
+ parsedFrames = parsedFrames.filter(f => {
58
+ if (filterPrefixes.some(prefix => f.frame.file.startsWith(prefix))) return false;
59
+ return true;
60
+ });
61
+ return {
62
+ frames: parsedFrames.map(p => p.frame),
63
+ apiName
64
+ };
65
+ }
@@ -4,35 +4,34 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.Connection = void 0;
7
+ var _eventEmitter = require("./eventEmitter");
8
+ var _android = require("./android");
9
+ var _artifact = require("./artifact");
7
10
  var _browser = require("./browser");
8
11
  var _browserContext = require("./browserContext");
9
12
  var _browserType = require("./browserType");
13
+ var _cdpSession = require("./cdpSession");
10
14
  var _channelOwner = require("./channelOwner");
15
+ var _clientInstrumentation = require("./clientInstrumentation");
16
+ var _dialog = require("./dialog");
17
+ var _electron = require("./electron");
11
18
  var _elementHandle = require("./elementHandle");
19
+ var _errors = require("./errors");
20
+ var _fetch = require("./fetch");
12
21
  var _frame = require("./frame");
13
22
  var _jsHandle = require("./jsHandle");
23
+ var _jsonPipe = require("./jsonPipe");
24
+ var _localUtils = require("./localUtils");
14
25
  var _network = require("./network");
15
26
  var _page = require("./page");
16
- var _worker = require("./worker");
17
- var _dialog = require("./dialog");
18
- var _errors = require("./errors");
19
- var _cdpSession = require("./cdpSession");
20
27
  var _playwright = require("./playwright");
21
- var _electron = require("./electron");
22
- var _stream = require("./stream");
23
- var _writableStream = require("./writableStream");
24
- var _debugLogger = require("../utils/debugLogger");
25
28
  var _selectors = require("./selectors");
26
- var _android = require("./android");
27
- var _artifact = require("./artifact");
28
- var _events = require("events");
29
- var _jsonPipe = require("./jsonPipe");
30
- var _fetch = require("./fetch");
31
- var _localUtils = require("./localUtils");
29
+ var _stream = require("./stream");
32
30
  var _tracing = require("./tracing");
31
+ var _worker = require("./worker");
32
+ var _writableStream = require("./writableStream");
33
33
  var _validator = require("../protocol/validator");
34
- var _clientInstrumentation = require("./clientInstrumentation");
35
- var _utils = require("../utils");
34
+ var _stackTrace = require("../utils/isomorphic/stackTrace");
36
35
  /**
37
36
  * Copyright (c) Microsoft Corporation.
38
37
  *
@@ -60,9 +59,9 @@ class Root extends _channelOwner.ChannelOwner {
60
59
  }
61
60
  }
62
61
  class DummyChannelOwner extends _channelOwner.ChannelOwner {}
63
- class Connection extends _events.EventEmitter {
64
- constructor(localUtils, instrumentation) {
65
- super();
62
+ class Connection extends _eventEmitter.EventEmitter {
63
+ constructor(platform, localUtils, instrumentation, headers = []) {
64
+ super(platform);
66
65
  this._objects = new Map();
67
66
  this.onmessage = message => {};
68
67
  this._lastId = 0;
@@ -76,9 +75,12 @@ class Connection extends _events.EventEmitter {
76
75
  this.toImpl = void 0;
77
76
  this._tracingCount = 0;
78
77
  this._instrumentation = void 0;
78
+ // Used from @playwright/test fixtures -> TODO remove?
79
+ this.headers = void 0;
79
80
  this._instrumentation = instrumentation || (0, _clientInstrumentation.createInstrumentation)();
80
81
  this._localUtils = localUtils;
81
82
  this._rootObject = new Root(this);
83
+ this.headers = headers;
82
84
  }
83
85
  markAsRemote() {
84
86
  this._isRemote = true;
@@ -117,9 +119,9 @@ class Connection extends _events.EventEmitter {
117
119
  method,
118
120
  params
119
121
  };
120
- if (_debugLogger.debugLogger.isEnabled('channel')) {
122
+ if (this._platform.isLogEnabled('channel')) {
121
123
  // Do not include metadata in debug logs to avoid noise.
122
- _debugLogger.debugLogger.log('channel', 'SEND> ' + JSON.stringify(message));
124
+ this._platform.log('channel', 'SEND> ' + JSON.stringify(message));
123
125
  }
124
126
  const location = frames[0] ? {
125
127
  file: frames[0].file,
@@ -132,7 +134,7 @@ class Connection extends _events.EventEmitter {
132
134
  internal: !apiName,
133
135
  stepId
134
136
  };
135
- if (this._tracingCount && frames && type !== 'LocalUtils') (_this$_localUtils = this._localUtils) === null || _this$_localUtils === void 0 || _this$_localUtils._channel.addStackToTracingNoReply({
137
+ if (this._tracingCount && frames && type !== 'LocalUtils') (_this$_localUtils = this._localUtils) === null || _this$_localUtils === void 0 || _this$_localUtils.addStackToTracingNoReply({
136
138
  callData: {
137
139
  stack: frames,
138
140
  id
@@ -140,7 +142,7 @@ class Connection extends _events.EventEmitter {
140
142
  }).catch(() => {});
141
143
  // We need to exit zones before calling into the server, otherwise
142
144
  // when we receive events from the server, we would be in an API zone.
143
- _utils.zones.empty().run(() => this.onmessage({
145
+ this._platform.zones.empty.run(() => this.onmessage({
144
146
  ...message,
145
147
  metadata
146
148
  }));
@@ -152,6 +154,13 @@ class Connection extends _events.EventEmitter {
152
154
  method
153
155
  }));
154
156
  }
157
+ _validatorFromWireContext() {
158
+ return {
159
+ tChannelImpl: this._tChannelImplFromWire.bind(this),
160
+ binary: this._rawBuffers ? 'buffer' : 'fromBase64',
161
+ isUnderTest: () => this._platform.isUnderTest()
162
+ };
163
+ }
155
164
  dispatch(message) {
156
165
  if (this._closedError) return;
157
166
  const {
@@ -164,24 +173,21 @@ class Connection extends _events.EventEmitter {
164
173
  log
165
174
  } = message;
166
175
  if (id) {
167
- if (_debugLogger.debugLogger.isEnabled('channel')) _debugLogger.debugLogger.log('channel', '<RECV ' + JSON.stringify(message));
176
+ if (this._platform.isLogEnabled('channel')) this._platform.log('channel', '<RECV ' + JSON.stringify(message));
168
177
  const callback = this._callbacks.get(id);
169
178
  if (!callback) throw new Error(`Cannot find command to respond: ${id}`);
170
179
  this._callbacks.delete(id);
171
180
  if (error && !result) {
172
181
  const parsedError = (0, _errors.parseError)(error);
173
- (0, _utils.rewriteErrorMessage)(parsedError, parsedError.message + (0, _utils.formatCallLog)(log));
182
+ (0, _stackTrace.rewriteErrorMessage)(parsedError, parsedError.message + formatCallLog(this._platform, log));
174
183
  callback.reject(parsedError);
175
184
  } else {
176
185
  const validator = (0, _validator.findValidator)(callback.type, callback.method, 'Result');
177
- callback.resolve(validator(result, '', {
178
- tChannelImpl: this._tChannelImplFromWire.bind(this),
179
- binary: this._rawBuffers ? 'buffer' : 'fromBase64'
180
- }));
186
+ callback.resolve(validator(result, '', this._validatorFromWireContext()));
181
187
  }
182
188
  return;
183
189
  }
184
- if (_debugLogger.debugLogger.isEnabled('channel')) _debugLogger.debugLogger.log('channel', '<EVENT ' + JSON.stringify(message));
190
+ if (this._platform.isLogEnabled('channel')) this._platform.log('channel', '<EVENT ' + JSON.stringify(message));
185
191
  if (method === '__create__') {
186
192
  this._createRemoteObject(guid, params.type, params.guid, params.initializer);
187
193
  return;
@@ -199,10 +205,7 @@ class Connection extends _events.EventEmitter {
199
205
  return;
200
206
  }
201
207
  const validator = (0, _validator.findValidator)(object._type, method, 'Event');
202
- object._channel.emit(method, validator(params, '', {
203
- tChannelImpl: this._tChannelImplFromWire.bind(this),
204
- binary: this._rawBuffers ? 'buffer' : 'fromBase64'
205
- }));
208
+ object._channel.emit(method, validator(params, '', this._validatorFromWireContext()));
206
209
  }
207
210
  close(cause) {
208
211
  if (this._closedError) return;
@@ -225,10 +228,7 @@ class Connection extends _events.EventEmitter {
225
228
  if (!parent) throw new Error(`Cannot find parent object ${parentGuid} to create ${guid}`);
226
229
  let result;
227
230
  const validator = (0, _validator.findValidator)(type, '', 'Initializer');
228
- initializer = validator(initializer, '', {
229
- tChannelImpl: this._tChannelImplFromWire.bind(this),
230
- binary: this._rawBuffers ? 'buffer' : 'fromBase64'
231
- });
231
+ initializer = validator(initializer, '', this._validatorFromWireContext());
232
232
  switch (type) {
233
233
  case 'Android':
234
234
  result = new _android.Android(parent, type, guid, initializer);
@@ -330,4 +330,11 @@ class Connection extends _events.EventEmitter {
330
330
  return result;
331
331
  }
332
332
  }
333
- exports.Connection = Connection;
333
+ exports.Connection = Connection;
334
+ function formatCallLog(platform, log) {
335
+ if (!log || !log.some(l => !!l)) return '';
336
+ return `
337
+ Call log:
338
+ ${platform.colors.dim(log.join('\n'))}
339
+ `;
340
+ }
@@ -4,10 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.ConsoleMessage = void 0;
7
- var util = _interopRequireWildcard(require("util"));
8
7
  var _jsHandle = require("./jsHandle");
9
8
  var _page = require("./page");
10
- let _util$inspect$custom;
11
9
  /**
12
10
  * Copyright (c) Microsoft Corporation.
13
11
  *
@@ -23,15 +21,14 @@ let _util$inspect$custom;
23
21
  * See the License for the specific language governing permissions and
24
22
  * limitations under the License.
25
23
  */
26
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
27
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
28
- _util$inspect$custom = util.inspect.custom;
24
+
29
25
  class ConsoleMessage {
30
- constructor(event) {
26
+ constructor(platform, event) {
31
27
  this._page = void 0;
32
28
  this._event = void 0;
33
29
  this._page = 'page' in event && event.page ? _page.Page.from(event.page) : null;
34
30
  this._event = event;
31
+ if (platform.inspectCustom) this[platform.inspectCustom] = () => this._inspect();
35
32
  }
36
33
  page() {
37
34
  return this._page;
@@ -48,7 +45,7 @@ class ConsoleMessage {
48
45
  location() {
49
46
  return this._event.location;
50
47
  }
51
- [_util$inspect$custom]() {
48
+ _inspect() {
52
49
  return this.text();
53
50
  }
54
51
  }
@@ -4,16 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.ElectronApplication = exports.Electron = void 0;
7
- var _timeoutSettings = require("../common/timeoutSettings");
8
7
  var _browserContext = require("./browserContext");
9
8
  var _channelOwner = require("./channelOwner");
10
9
  var _clientHelper = require("./clientHelper");
10
+ var _consoleMessage = require("./consoleMessage");
11
+ var _errors = require("./errors");
11
12
  var _events = require("./events");
12
13
  var _jsHandle = require("./jsHandle");
13
- var _consoleMessage = require("./consoleMessage");
14
14
  var _waiter = require("./waiter");
15
- var _errors = require("./errors");
16
- let _Symbol$asyncDispose;
15
+ var _timeoutSettings = require("./timeoutSettings");
17
16
  /**
18
17
  * Copyright (c) Microsoft Corporation.
19
18
  *
@@ -29,6 +28,7 @@ let _Symbol$asyncDispose;
29
28
  * See the License for the specific language governing permissions and
30
29
  * limitations under the License.
31
30
  */
31
+
32
32
  class Electron extends _channelOwner.ChannelOwner {
33
33
  static from(electron) {
34
34
  return electron._object;
@@ -38,8 +38,8 @@ class Electron extends _channelOwner.ChannelOwner {
38
38
  }
39
39
  async launch(options = {}) {
40
40
  const params = {
41
- ...(await (0, _browserContext.prepareBrowserContextParams)(options)),
42
- env: (0, _clientHelper.envObjectToArray)(options.env ? options.env : process.env),
41
+ ...(await (0, _browserContext.prepareBrowserContextParams)(this._platform, options)),
42
+ env: (0, _clientHelper.envObjectToArray)(options.env ? options.env : this._platform.env),
43
43
  tracesDir: options.tracesDir
44
44
  };
45
45
  const app = ElectronApplication.from((await this._channel.launch(params)).electronApplication);
@@ -48,7 +48,6 @@ class Electron extends _channelOwner.ChannelOwner {
48
48
  }
49
49
  }
50
50
  exports.Electron = Electron;
51
- _Symbol$asyncDispose = Symbol.asyncDispose;
52
51
  class ElectronApplication extends _channelOwner.ChannelOwner {
53
52
  static from(electronApplication) {
54
53
  return electronApplication._object;
@@ -57,14 +56,15 @@ class ElectronApplication extends _channelOwner.ChannelOwner {
57
56
  super(parent, type, guid, initializer);
58
57
  this._context = void 0;
59
58
  this._windows = new Set();
60
- this._timeoutSettings = new _timeoutSettings.TimeoutSettings();
59
+ this._timeoutSettings = void 0;
60
+ this._timeoutSettings = new _timeoutSettings.TimeoutSettings(this._platform);
61
61
  this._context = _browserContext.BrowserContext.from(initializer.context);
62
62
  for (const page of this._context._pages) this._onPage(page);
63
63
  this._context.on(_events.Events.BrowserContext.Page, page => this._onPage(page));
64
64
  this._channel.on('close', () => {
65
65
  this.emit(_events.Events.ElectronApplication.Close);
66
66
  });
67
- this._channel.on('console', event => this.emit(_events.Events.ElectronApplication.Console, new _consoleMessage.ConsoleMessage(event)));
67
+ this._channel.on('console', event => this.emit(_events.Events.ElectronApplication.Console, new _consoleMessage.ConsoleMessage(this._platform, event)));
68
68
  this._setEventToSubscriptionMapping(new Map([[_events.Events.ElectronApplication.Console, 'console']]));
69
69
  }
70
70
  process() {
@@ -86,7 +86,7 @@ class ElectronApplication extends _channelOwner.ChannelOwner {
86
86
  context() {
87
87
  return this._context;
88
88
  }
89
- async [_Symbol$asyncDispose]() {
89
+ async [Symbol.asyncDispose]() {
90
90
  await this.close();
91
91
  }
92
92
  async close() {
@@ -9,15 +9,11 @@ exports.convertSelectOptionValues = convertSelectOptionValues;
9
9
  exports.determineScreenshotType = determineScreenshotType;
10
10
  var _frame = require("./frame");
11
11
  var _jsHandle = require("./jsHandle");
12
- var _fs = _interopRequireDefault(require("fs"));
13
- var _utilsBundle = require("../utilsBundle");
14
- var _path = _interopRequireDefault(require("path"));
15
- var _utils = require("../utils");
16
- var _fileUtils = require("../utils/fileUtils");
12
+ var _assert = require("../utils/isomorphic/assert");
13
+ var _fileUtils = require("./fileUtils");
14
+ var _rtti = require("../utils/isomorphic/rtti");
17
15
  var _writableStream = require("./writableStream");
18
- var _stream = require("stream");
19
- var _util = require("util");
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
+ var _mimeType = require("../utils/isomorphic/mimeType");
21
17
  /**
22
18
  * Copyright (c) Microsoft Corporation.
23
19
  *
@@ -34,7 +30,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
34
30
  * limitations under the License.
35
31
  */
36
32
 
37
- const pipelineAsync = (0, _util.promisify)(_stream.pipeline);
38
33
  class ElementHandle extends _jsHandle.JSHandle {
39
34
  static from(handle) {
40
35
  return handle._object;
@@ -56,6 +51,10 @@ class ElementHandle extends _jsHandle.JSHandle {
56
51
  async contentFrame() {
57
52
  return _frame.Frame.fromNullable((await this._elementChannel.contentFrame()).frame);
58
53
  }
54
+ async _generateLocatorString() {
55
+ const value = (await this._elementChannel.generateLocatorString()).value;
56
+ return value === undefined ? null : value;
57
+ }
59
58
  async getAttribute(name) {
60
59
  const value = (await this._elementChannel.getAttribute({
61
60
  name
@@ -133,7 +132,7 @@ class ElementHandle extends _jsHandle.JSHandle {
133
132
  async setInputFiles(files, options = {}) {
134
133
  const frame = await this.ownerFrame();
135
134
  if (!frame) throw new Error('Cannot set input files to detached element');
136
- const converted = await convertInputFiles(files, frame.page().context());
135
+ const converted = await convertInputFiles(this._platform, files, frame.page().context());
137
136
  await this._elementChannel.setInputFiles({
138
137
  ...converted,
139
138
  ...options
@@ -168,21 +167,22 @@ class ElementHandle extends _jsHandle.JSHandle {
168
167
  return value === undefined ? null : value;
169
168
  }
170
169
  async screenshot(options = {}) {
170
+ const mask = options.mask;
171
171
  const copy = {
172
172
  ...options,
173
173
  mask: undefined
174
174
  };
175
175
  if (!copy.type) copy.type = determineScreenshotType(options);
176
- if (options.mask) {
177
- copy.mask = options.mask.map(locator => ({
176
+ if (mask) {
177
+ copy.mask = mask.map(locator => ({
178
178
  frame: locator._frame._channel,
179
179
  selector: locator._selector
180
180
  }));
181
181
  }
182
182
  const result = await this._elementChannel.screenshot(copy);
183
183
  if (options.path) {
184
- await (0, _fileUtils.mkdirIfNeeded)(options.path);
185
- await _fs.default.promises.writeFile(options.path, result.binary);
184
+ await (0, _fileUtils.mkdirIfNeeded)(this._platform, options.path);
185
+ await this._platform.fs().promises.writeFile(options.path, result.binary);
186
186
  }
187
187
  return result.binary;
188
188
  }
@@ -234,11 +234,11 @@ function convertSelectOptionValues(values) {
234
234
  if (values === null) return {};
235
235
  if (!Array.isArray(values)) values = [values];
236
236
  if (!values.length) return {};
237
- for (let i = 0; i < values.length; i++) (0, _utils.assert)(values[i] !== null, `options[${i}]: expected object, got null`);
237
+ for (let i = 0; i < values.length; i++) (0, _assert.assert)(values[i] !== null, `options[${i}]: expected object, got null`);
238
238
  if (values[0] instanceof ElementHandle) return {
239
239
  elements: values.map(v => v._elementChannel)
240
240
  };
241
- if ((0, _utils.isString)(values[0])) return {
241
+ if ((0, _rtti.isString)(values[0])) return {
242
242
  options: values.map(valueOrLabel => ({
243
243
  valueOrLabel
244
244
  }))
@@ -250,50 +250,49 @@ function convertSelectOptionValues(values) {
250
250
  function filePayloadExceedsSizeLimit(payloads) {
251
251
  return payloads.reduce((size, item) => size + (item.buffer ? item.buffer.byteLength : 0), 0) >= _fileUtils.fileUploadSizeLimit;
252
252
  }
253
- async function resolvePathsAndDirectoryForInputFiles(items) {
254
- var _localPaths2;
253
+ async function resolvePathsAndDirectoryForInputFiles(platform, items) {
254
+ var _localPaths;
255
255
  let localPaths;
256
256
  let localDirectory;
257
257
  for (const item of items) {
258
- const stat = await _fs.default.promises.stat(item);
258
+ const stat = await platform.fs().promises.stat(item);
259
259
  if (stat.isDirectory()) {
260
260
  if (localDirectory) throw new Error('Multiple directories are not supported');
261
- localDirectory = _path.default.resolve(item);
261
+ localDirectory = platform.path().resolve(item);
262
262
  } else {
263
- var _localPaths;
264
- (_localPaths = localPaths) !== null && _localPaths !== void 0 ? _localPaths : localPaths = [];
265
- localPaths.push(_path.default.resolve(item));
263
+ localPaths !== null && localPaths !== void 0 ? localPaths : localPaths = [];
264
+ localPaths.push(platform.path().resolve(item));
266
265
  }
267
266
  }
268
- if ((_localPaths2 = localPaths) !== null && _localPaths2 !== void 0 && _localPaths2.length && localDirectory) throw new Error('File paths must be all files or a single directory');
267
+ if ((_localPaths = localPaths) !== null && _localPaths !== void 0 && _localPaths.length && localDirectory) throw new Error('File paths must be all files or a single directory');
269
268
  return [localPaths, localDirectory];
270
269
  }
271
- async function convertInputFiles(files, context) {
270
+ async function convertInputFiles(platform, files, context) {
272
271
  const items = Array.isArray(files) ? files.slice() : [files];
273
272
  if (items.some(item => typeof item === 'string')) {
274
273
  if (!items.every(item => typeof item === 'string')) throw new Error('File paths cannot be mixed with buffers');
275
- const [localPaths, localDirectory] = await resolvePathsAndDirectoryForInputFiles(items);
274
+ const [localPaths, localDirectory] = await resolvePathsAndDirectoryForInputFiles(platform, items);
276
275
  if (context._connection.isRemote()) {
277
- const files = localDirectory ? (await _fs.default.promises.readdir(localDirectory, {
276
+ const files = localDirectory ? (await platform.fs().promises.readdir(localDirectory, {
278
277
  withFileTypes: true,
279
278
  recursive: true
280
- })).filter(f => f.isFile()).map(f => _path.default.join(f.path, f.name)) : localPaths;
279
+ })).filter(f => f.isFile()).map(f => platform.path().join(f.path, f.name)) : localPaths;
281
280
  const {
282
281
  writableStreams,
283
282
  rootDir
284
283
  } = await context._wrapApiCall(async () => context._channel.createTempFiles({
285
- rootDirName: localDirectory ? _path.default.basename(localDirectory) : undefined,
284
+ rootDirName: localDirectory ? platform.path().basename(localDirectory) : undefined,
286
285
  items: await Promise.all(files.map(async file => {
287
- const lastModifiedMs = (await _fs.default.promises.stat(file)).mtimeMs;
286
+ const lastModifiedMs = (await platform.fs().promises.stat(file)).mtimeMs;
288
287
  return {
289
- name: localDirectory ? _path.default.relative(localDirectory, file) : _path.default.basename(file),
288
+ name: localDirectory ? platform.path().relative(localDirectory, file) : platform.path().basename(file),
290
289
  lastModifiedMs
291
290
  };
292
291
  }))
293
292
  }), true);
294
293
  for (let i = 0; i < files.length; i++) {
295
294
  const writable = _writableStream.WritableStream.from(writableStreams[i]);
296
- await pipelineAsync(_fs.default.createReadStream(files[i]), writable.stream());
295
+ await platform.streamFile(files[i], writable.stream());
297
296
  }
298
297
  return {
299
298
  directoryStream: rootDir,
@@ -313,7 +312,7 @@ async function convertInputFiles(files, context) {
313
312
  }
314
313
  function determineScreenshotType(options) {
315
314
  if (options.path) {
316
- const mimeType = _utilsBundle.mime.getType(options.path);
315
+ const mimeType = (0, _mimeType.getMimeTypeForPath)(options.path);
317
316
  if (mimeType === 'image/png') return 'png';else if (mimeType === 'image/jpeg') return 'jpeg';
318
317
  throw new Error(`path: unsupported mime type "${mimeType}"`);
319
318
  }
@@ -7,8 +7,8 @@ exports.TimeoutError = exports.TargetClosedError = void 0;
7
7
  exports.isTargetClosedError = isTargetClosedError;
8
8
  exports.parseError = parseError;
9
9
  exports.serializeError = serializeError;
10
- var _utils = require("../utils");
11
10
  var _serializers = require("../protocol/serializers");
11
+ var _rtti = require("../utils/isomorphic/rtti");
12
12
  /**
13
13
  * Copyright (c) Microsoft Corporation.
14
14
  *
@@ -42,7 +42,7 @@ function isTargetClosedError(error) {
42
42
  return error instanceof TargetClosedError;
43
43
  }
44
44
  function serializeError(e) {
45
- if ((0, _utils.isError)(e)) return {
45
+ if ((0, _rtti.isError)(e)) return {
46
46
  error: {
47
47
  message: e.message,
48
48
  stack: e.stack,
@@ -4,8 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.EventEmitter = void 0;
7
- var _events = require("events");
8
- var _utils = require("../utils");
9
7
  /**
10
8
  * Copyright Joyent, Inc. and other Node contributors.
11
9
  * Modifications copyright (c) Microsoft Corporation.
@@ -31,12 +29,14 @@ var _utils = require("../utils");
31
29
  */
32
30
 
33
31
  class EventEmitter {
34
- constructor() {
32
+ constructor(platform) {
35
33
  this._events = undefined;
36
34
  this._eventsCount = 0;
37
35
  this._maxListeners = undefined;
38
36
  this._pendingHandlers = new Map();
39
37
  this._rejectionHandler = void 0;
38
+ this._platform = void 0;
39
+ this._platform = platform;
40
40
  if (this._events === undefined || this._events === Object.getPrototypeOf(this)._events) {
41
41
  this._events = Object.create(null);
42
42
  this._eventsCount = 0;
@@ -51,7 +51,7 @@ class EventEmitter {
51
51
  return this;
52
52
  }
53
53
  getMaxListeners() {
54
- return this._maxListeners === undefined ? _events.EventEmitter.defaultMaxListeners : this._maxListeners;
54
+ return this._maxListeners === undefined ? this._platform.defaultMaxListeners() : this._maxListeners;
55
55
  }
56
56
  emit(type, ...args) {
57
57
  const events = this._events;
@@ -130,7 +130,7 @@ class EventEmitter {
130
130
  w.emitter = this;
131
131
  w.type = type;
132
132
  w.count = existing.length;
133
- if (!(0, _utils.isUnderTest)()) {
133
+ if (!this._platform.isUnderTest()) {
134
134
  // eslint-disable-next-line no-console
135
135
  console.warn(w);
136
136
  }
@@ -191,14 +191,11 @@ class EventEmitter {
191
191
  if (options.behavior === 'wait') {
192
192
  const errors = [];
193
193
  this._rejectionHandler = error => errors.push(error);
194
- // eslint-disable-next-line internal-playwright/await-promise-in-class-returns
195
194
  return this._waitFor(type).then(() => {
196
195
  if (errors.length) throw errors[0];
197
196
  });
198
197
  }
199
198
  if (options.behavior === 'ignoreErrors') this._rejectionHandler = () => {};
200
-
201
- // eslint-disable-next-line internal-playwright/await-promise-in-class-returns
202
199
  return Promise.resolve();
203
200
  }
204
201
  _removeAllListeners(type) {