patchright-core 1.50.1 → 1.51.0

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
@@ -4,11 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.Page = exports.BindingCall = void 0;
7
- var _fs = _interopRequireDefault(require("fs"));
8
- var _path = _interopRequireDefault(require("path"));
9
- var _errors = require("./errors");
10
- var _timeoutSettings = require("../common/timeoutSettings");
11
- var _utils = require("../utils");
12
7
  var _accessibility = require("./accessibility");
13
8
  var _artifact = require("./artifact");
14
9
  var _channelOwner = require("./channelOwner");
@@ -16,17 +11,25 @@ var _clientHelper = require("./clientHelper");
16
11
  var _coverage = require("./coverage");
17
12
  var _download = require("./download");
18
13
  var _elementHandle = require("./elementHandle");
14
+ var _errors = require("./errors");
19
15
  var _events = require("./events");
20
16
  var _fileChooser = require("./fileChooser");
21
17
  var _frame = require("./frame");
18
+ var _harRouter = require("./harRouter");
22
19
  var _input = require("./input");
23
20
  var _jsHandle = require("./jsHandle");
24
21
  var _network = require("./network");
25
22
  var _video = require("./video");
26
23
  var _waiter = require("./waiter");
27
24
  var _worker = require("./worker");
28
- var _harRouter = require("./harRouter");
29
- let _Symbol$asyncDispose;
25
+ var _timeoutSettings = require("./timeoutSettings");
26
+ var _assert = require("../utils/isomorphic/assert");
27
+ var _fileUtils = require("./fileUtils");
28
+ var _headers = require("../utils/isomorphic/headers");
29
+ var _stringUtils = require("../utils/isomorphic/stringUtils");
30
+ var _urlMatch = require("../utils/isomorphic/urlMatch");
31
+ var _manualPromise = require("../utils/isomorphic/manualPromise");
32
+ var _rtti = require("../utils/isomorphic/rtti");
30
33
  /**
31
34
  * Copyright 2017 Google Inc. All rights reserved.
32
35
  * Modifications copyright (c) Microsoft Corporation.
@@ -43,8 +46,7 @@ let _Symbol$asyncDispose;
43
46
  * See the License for the specific language governing permissions and
44
47
  * limitations under the License.
45
48
  */
46
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
47
- _Symbol$asyncDispose = Symbol.asyncDispose;
49
+
48
50
  class Page extends _channelOwner.ChannelOwner {
49
51
  static from(page) {
50
52
  return page._object;
@@ -60,7 +62,7 @@ class Page extends _channelOwner.ChannelOwner {
60
62
  this._frames = new Set();
61
63
  this._workers = new Set();
62
64
  this._closed = false;
63
- this._closedOrCrashedScope = new _utils.LongStandingScope();
65
+ this._closedOrCrashedScope = new _manualPromise.LongStandingScope();
64
66
  this._viewportSize = void 0;
65
67
  this._routes = [];
66
68
  this._webSocketRoutes = [];
@@ -81,7 +83,7 @@ class Page extends _channelOwner.ChannelOwner {
81
83
  this._locatorHandlers = new Map();
82
84
  this.routeInjecting = false;
83
85
  this._browserContext = parent;
84
- this._timeoutSettings = new _timeoutSettings.TimeoutSettings(this._browserContext._timeoutSettings);
86
+ this._timeoutSettings = new _timeoutSettings.TimeoutSettings(this._platform, this._browserContext._timeoutSettings);
85
87
  this.accessibility = new _accessibility.Accessibility(this._channel);
86
88
  this.keyboard = new _input.Keyboard(this);
87
89
  this.mouse = new _input.Mouse(this);
@@ -209,12 +211,12 @@ class Page extends _channelOwner.ChannelOwner {
209
211
  return this._mainFrame;
210
212
  }
211
213
  frame(frameSelector) {
212
- const name = (0, _utils.isString)(frameSelector) ? frameSelector : frameSelector.name;
213
- const url = (0, _utils.isObject)(frameSelector) ? frameSelector.url : undefined;
214
- (0, _utils.assert)(name || url, 'Either name or url matcher should be specified');
214
+ const name = (0, _rtti.isString)(frameSelector) ? frameSelector : frameSelector.name;
215
+ const url = (0, _rtti.isObject)(frameSelector) ? frameSelector.url : undefined;
216
+ (0, _assert.assert)(name || url, 'Either name or url matcher should be specified');
215
217
  return this.frames().find(f => {
216
218
  if (name) return f.name() === name;
217
- return (0, _utils.urlMatches)(this._browserContext._options.baseURL, f.url(), url);
219
+ return (0, _urlMatch.urlMatches)(this._browserContext._options.baseURL, f.url(), url);
218
220
  }) || null;
219
221
  }
220
222
  frames() {
@@ -223,18 +225,18 @@ class Page extends _channelOwner.ChannelOwner {
223
225
  setDefaultNavigationTimeout(timeout) {
224
226
  this._timeoutSettings.setDefaultNavigationTimeout(timeout);
225
227
  this._wrapApiCall(async () => {
226
- this._channel.setDefaultNavigationTimeoutNoReply({
228
+ await this._channel.setDefaultNavigationTimeoutNoReply({
227
229
  timeout
228
- }).catch(() => {});
229
- }, true);
230
+ });
231
+ }, true).catch(() => {});
230
232
  }
231
233
  setDefaultTimeout(timeout) {
232
234
  this._timeoutSettings.setDefaultTimeout(timeout);
233
235
  this._wrapApiCall(async () => {
234
- this._channel.setDefaultTimeoutNoReply({
236
+ await this._channel.setDefaultTimeoutNoReply({
235
237
  timeout
236
- }).catch(() => {});
237
- }, true);
238
+ });
239
+ }, true).catch(() => {});
238
240
  }
239
241
  _forceVideo() {
240
242
  if (!this._video) this._video = new _video.Video(this, this._connection);
@@ -256,9 +258,9 @@ class Page extends _channelOwner.ChannelOwner {
256
258
  async dispatchEvent(selector, type, eventInit, options) {
257
259
  return await this._mainFrame.dispatchEvent(selector, type, eventInit, options);
258
260
  }
259
- async evaluateHandle(pageFunction, arg) {
260
- (0, _jsHandle.assertMaxArguments)(arguments.length, 2);
261
- return await this._mainFrame.evaluateHandle(pageFunction, arg);
261
+ async evaluateHandle(pageFunction, arg, isolatedContext = true) {
262
+ (0, _jsHandle.assertMaxArguments)(arguments.length, 3);
263
+ return await this._mainFrame.evaluateHandle(pageFunction, arg, isolatedContext);
262
264
  }
263
265
  async $eval(selector, pageFunction, arg) {
264
266
  (0, _jsHandle.assertMaxArguments)(arguments.length, 3);
@@ -296,7 +298,7 @@ class Page extends _channelOwner.ChannelOwner {
296
298
  async setExtraHTTPHeaders(headers) {
297
299
  (0, _network.validateHeaders)(headers);
298
300
  await this._channel.setExtraHTTPHeaders({
299
- headers: (0, _utils.headersObjectToArray)(headers)
301
+ headers: (0, _headers.headersObjectToArray)(headers)
300
302
  });
301
303
  }
302
304
  url() {
@@ -371,7 +373,7 @@ class Page extends _channelOwner.ChannelOwner {
371
373
  }
372
374
  async waitForRequest(urlOrPredicate, options = {}) {
373
375
  const predicate = async request => {
374
- if ((0, _utils.isString)(urlOrPredicate) || (0, _utils.isRegExp)(urlOrPredicate)) return (0, _utils.urlMatches)(this._browserContext._options.baseURL, request.url(), urlOrPredicate);
376
+ if ((0, _rtti.isString)(urlOrPredicate) || (0, _rtti.isRegExp)(urlOrPredicate)) return (0, _urlMatch.urlMatches)(this._browserContext._options.baseURL, request.url(), urlOrPredicate);
375
377
  return await urlOrPredicate(request);
376
378
  };
377
379
  const trimmedUrl = trimUrl(urlOrPredicate);
@@ -383,7 +385,7 @@ class Page extends _channelOwner.ChannelOwner {
383
385
  }
384
386
  async waitForResponse(urlOrPredicate, options = {}) {
385
387
  const predicate = async response => {
386
- if ((0, _utils.isString)(urlOrPredicate) || (0, _utils.isRegExp)(urlOrPredicate)) return (0, _utils.urlMatches)(this._browserContext._options.baseURL, response.url(), urlOrPredicate);
388
+ if ((0, _rtti.isString)(urlOrPredicate) || (0, _rtti.isRegExp)(urlOrPredicate)) return (0, _urlMatch.urlMatches)(this._browserContext._options.baseURL, response.url(), urlOrPredicate);
387
389
  return await urlOrPredicate(response);
388
390
  };
389
391
  const trimmedUrl = trimUrl(urlOrPredicate);
@@ -435,7 +437,8 @@ class Page extends _channelOwner.ChannelOwner {
435
437
  media: options.media === null ? 'no-override' : options.media,
436
438
  colorScheme: options.colorScheme === null ? 'no-override' : options.colorScheme,
437
439
  reducedMotion: options.reducedMotion === null ? 'no-override' : options.reducedMotion,
438
- forcedColors: options.forcedColors === null ? 'no-override' : options.forcedColors
440
+ forcedColors: options.forcedColors === null ? 'no-override' : options.forcedColors,
441
+ contrast: options.contrast === null ? 'no-override' : options.contrast
439
442
  });
440
443
  }
441
444
  async setViewportSize(viewportSize) {
@@ -447,27 +450,29 @@ class Page extends _channelOwner.ChannelOwner {
447
450
  viewportSize() {
448
451
  return this._viewportSize;
449
452
  }
450
- async evaluate(pageFunction, arg) {
451
- (0, _jsHandle.assertMaxArguments)(arguments.length, 2);
452
- return await this._mainFrame.evaluate(pageFunction, arg);
453
+ async evaluate(pageFunction, arg, isolatedContext = true) {
454
+ (0, _jsHandle.assertMaxArguments)(arguments.length, 3);
455
+ return await this._mainFrame.evaluate(pageFunction, arg, isolatedContext);
453
456
  }
454
457
  async addInitScript(script, arg) {
455
458
  await this.installInjectRoute();
456
- const source = await (0, _clientHelper.evaluationScript)(script, arg);
459
+ const source = await (0, _clientHelper.evaluationScript)(this._platform, script, arg);
457
460
  await this._channel.addInitScript({
458
461
  source
459
462
  });
460
463
  }
461
464
  async route(url, handler, options = {}) {
462
- this._routes.unshift(new _network.RouteHandler(this._browserContext._options.baseURL, url, handler, options.times));
465
+ this._routes.unshift(new _network.RouteHandler(this._platform, this._browserContext._options.baseURL, url, handler, options.times));
463
466
  await this._updateInterceptionPatterns();
464
467
  }
465
468
  async routeFromHAR(har, options = {}) {
469
+ const localUtils = this._connection.localUtils();
470
+ if (!localUtils) throw new Error('Route from har is not supported in thin clients');
466
471
  if (options.update) {
467
472
  await this._browserContext._recordIntoHAR(har, this, options);
468
473
  return;
469
474
  }
470
- const harRouter = await _harRouter.HarRouter.create(this._connection.localUtils(), har, options.notFound || 'abort', {
475
+ const harRouter = await _harRouter.HarRouter.create(localUtils, har, options.notFound || 'abort', {
471
476
  urlMatch: options.url
472
477
  });
473
478
  this._harRouters.push(harRouter);
@@ -489,7 +494,7 @@ class Page extends _channelOwner.ChannelOwner {
489
494
  const removed = [];
490
495
  const remaining = [];
491
496
  for (const route of this._routes) {
492
- if ((0, _utils.urlMatchesEqual)(route.url, url) && (!handler || route.handler === handler)) removed.push(route);else remaining.push(route);
497
+ if ((0, _urlMatch.urlMatchesEqual)(route.url, url) && (!handler || route.handler === handler)) removed.push(route);else remaining.push(route);
493
498
  }
494
499
  await this._unrouteInternal(removed, remaining, 'default');
495
500
  }
@@ -513,21 +518,22 @@ class Page extends _channelOwner.ChannelOwner {
513
518
  });
514
519
  }
515
520
  async screenshot(options = {}) {
521
+ const mask = options.mask;
516
522
  const copy = {
517
523
  ...options,
518
524
  mask: undefined
519
525
  };
520
526
  if (!copy.type) copy.type = (0, _elementHandle.determineScreenshotType)(options);
521
- if (options.mask) {
522
- copy.mask = options.mask.map(locator => ({
527
+ if (mask) {
528
+ copy.mask = mask.map(locator => ({
523
529
  frame: locator._frame._channel,
524
530
  selector: locator._selector
525
531
  }));
526
532
  }
527
533
  const result = await this._channel.screenshot(copy);
528
534
  if (options.path) {
529
- await (0, _utils.mkdirIfNeeded)(options.path);
530
- await _fs.default.promises.writeFile(options.path, result.binary);
535
+ await (0, _fileUtils.mkdirIfNeeded)(this._platform, options.path);
536
+ await this._platform.fs().promises.writeFile(options.path, result.binary);
531
537
  }
532
538
  return result.binary;
533
539
  }
@@ -553,7 +559,7 @@ class Page extends _channelOwner.ChannelOwner {
553
559
  async bringToFront() {
554
560
  await this._channel.bringToFront();
555
561
  }
556
- async [_Symbol$asyncDispose]() {
562
+ async [Symbol.asyncDispose]() {
557
563
  await this.close();
558
564
  }
559
565
  async close(options = {}) {
@@ -682,7 +688,7 @@ class Page extends _channelOwner.ChannelOwner {
682
688
  }
683
689
  async pause(_options) {
684
690
  var _this$_instrumentatio;
685
- if (require('inspector').url()) return;
691
+ if (this._platform.isJSDebuggerAttached()) return;
686
692
  const defaultNavigationTimeout = this._browserContext._timeoutSettings.defaultNavigationTimeout();
687
693
  const defaultTimeout = this._browserContext._timeoutSettings.defaultTimeout();
688
694
  this._browserContext.setDefaultNavigationTimeout(0);
@@ -709,32 +715,30 @@ class Page extends _channelOwner.ChannelOwner {
709
715
  }
710
716
  const result = await this._channel.pdf(transportOptions);
711
717
  if (options.path) {
712
- await _fs.default.promises.mkdir(_path.default.dirname(options.path), {
718
+ const platform = this._platform;
719
+ await platform.fs().promises.mkdir(platform.path().dirname(options.path), {
713
720
  recursive: true
714
721
  });
715
- await _fs.default.promises.writeFile(options.path, result.pdf);
722
+ await platform.fs().promises.writeFile(options.path, result.pdf);
716
723
  }
717
724
  return result.pdf;
718
725
  }
719
726
  async installInjectRoute() {
720
727
  if (this.routeInjecting || this.context().routeInjecting) return;
721
728
  await this.route('**/*', async route => {
722
- if (route.request().resourceType() === 'document' && route.request().url().startsWith('http')) {
723
- try {
724
- const response = await route.fetch({
725
- maxRedirects: 0
726
- });
727
- await route.fulfill({
728
- response: response
729
+ try {
730
+ if (route.request().resourceType() === 'document' && route.request().url().startsWith('http')) {
731
+ const protocol = route.request().url().split(':')[0];
732
+ await route.continue({
733
+ url: protocol + '://patchright-init-script-inject.internal/'
729
734
  });
730
- } catch (e) {
735
+ } else {
731
736
  await route.continue();
732
737
  }
733
- } else {
738
+ } catch (error) {
734
739
  await route.continue();
735
740
  }
736
741
  });
737
- this.routeInjecting = true;
738
742
  }
739
743
  }
740
744
  exports.Page = Page;
@@ -767,6 +771,6 @@ class BindingCall extends _channelOwner.ChannelOwner {
767
771
  }
768
772
  exports.BindingCall = BindingCall;
769
773
  function trimUrl(param) {
770
- if ((0, _utils.isRegExp)(param)) return `/${(0, _utils.trimStringWithEllipsis)(param.source, 50)}/${param.flags}`;
771
- if ((0, _utils.isString)(param)) return `"${(0, _utils.trimStringWithEllipsis)(param, 50)}"`;
774
+ if ((0, _rtti.isRegExp)(param)) return `/${(0, _stringUtils.trimStringWithEllipsis)(param.source, 50)}/${param.flags}`;
775
+ if ((0, _rtti.isString)(param)) return `"${(0, _stringUtils.trimStringWithEllipsis)(param, 50)}"`;
772
776
  }
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.emptyPlatform = void 0;
7
+ var _colors = require("../utils/isomorphic/colors");
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
+ const noopZone = {
25
+ push: () => noopZone,
26
+ pop: () => noopZone,
27
+ run: func => func(),
28
+ data: () => undefined
29
+ };
30
+ const emptyPlatform = exports.emptyPlatform = {
31
+ name: 'empty',
32
+ boxedStackPrefixes: () => [],
33
+ calculateSha1: async () => {
34
+ throw new Error('Not implemented');
35
+ },
36
+ colors: _colors.webColors,
37
+ createGuid: () => {
38
+ throw new Error('Not implemented');
39
+ },
40
+ defaultMaxListeners: () => 10,
41
+ env: {},
42
+ fs: () => {
43
+ throw new Error('Not implemented');
44
+ },
45
+ inspectCustom: undefined,
46
+ isDebugMode: () => false,
47
+ isJSDebuggerAttached: () => false,
48
+ isLogEnabled(name) {
49
+ return false;
50
+ },
51
+ isUnderTest: () => false,
52
+ log(name, message) {},
53
+ path: () => {
54
+ throw new Error('Function not implemented.');
55
+ },
56
+ pathSeparator: '/',
57
+ showInternalStackFrames: () => false,
58
+ streamFile(path, writable) {
59
+ throw new Error('Streams are not available');
60
+ },
61
+ streamReadable: channel => {
62
+ throw new Error('Streams are not available');
63
+ },
64
+ streamWritable: channel => {
65
+ throw new Error('Streams are not available');
66
+ },
67
+ zones: {
68
+ empty: noopZone,
69
+ current: () => noopZone
70
+ }
71
+ };
@@ -4,11 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.Playwright = void 0;
7
- var _errors = require("./errors");
8
7
  var _android = require("./android");
8
+ var _browser = require("./browser");
9
9
  var _browserType = require("./browserType");
10
10
  var _channelOwner = require("./channelOwner");
11
11
  var _electron = require("./electron");
12
+ var _errors = require("./errors");
12
13
  var _fetch = require("./fetch");
13
14
  var _selectors = require("./selectors");
14
15
  /**
@@ -42,6 +43,11 @@ class Playwright extends _channelOwner.ChannelOwner {
42
43
  this.selectors = void 0;
43
44
  this.request = void 0;
44
45
  this.errors = void 0;
46
+ // Instrumentation.
47
+ this._defaultLaunchOptions = void 0;
48
+ this._defaultContextOptions = void 0;
49
+ this._defaultContextTimeout = void 0;
50
+ this._defaultContextNavigationTimeout = void 0;
45
51
  this.request = new _fetch.APIRequest(this);
46
52
  this.chromium = _browserType.BrowserType.from(initializer.chromium);
47
53
  this.chromium._playwright = this;
@@ -76,5 +82,19 @@ class Playwright extends _channelOwner.ChannelOwner {
76
82
  static from(channel) {
77
83
  return channel._object;
78
84
  }
85
+ _browserTypes() {
86
+ return [this.chromium, this.firefox, this.webkit, this._bidiChromium, this._bidiFirefox];
87
+ }
88
+ _preLaunchedBrowser() {
89
+ const browser = _browser.Browser.from(this._initializer.preLaunchedBrowser);
90
+ browser._browserType = this[browser._name];
91
+ return browser;
92
+ }
93
+ _allContexts() {
94
+ return this._browserTypes().flatMap(type => [...type._contexts]);
95
+ }
96
+ _allPages() {
97
+ return this._allContexts().flatMap(context => context.pages());
98
+ }
79
99
  }
80
100
  exports.Playwright = Playwright;
@@ -4,9 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.SelectorsOwner = exports.Selectors = void 0;
7
- var _clientHelper = require("./clientHelper");
7
+ exports.setPlatformForSelectors = setPlatformForSelectors;
8
8
  var _channelOwner = require("./channelOwner");
9
+ var _clientHelper = require("./clientHelper");
9
10
  var _locator = require("./locator");
11
+ var _platform = require("./platform");
10
12
  /**
11
13
  * Copyright (c) Microsoft Corporation.
12
14
  *
@@ -23,13 +25,17 @@ var _locator = require("./locator");
23
25
  * limitations under the License.
24
26
  */
25
27
 
28
+ let platform = _platform.emptyPlatform;
29
+ function setPlatformForSelectors(p) {
30
+ platform = p;
31
+ }
26
32
  class Selectors {
27
33
  constructor() {
28
34
  this._channels = new Set();
29
35
  this._registrations = [];
30
36
  }
31
37
  async register(name, script, options = {}) {
32
- const source = await (0, _clientHelper.evaluationScript)(script, undefined, false);
38
+ const source = await (0, _clientHelper.evaluationScript)(platform, script, undefined, false);
33
39
  const params = {
34
40
  ...options,
35
41
  name,
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.Stream = void 0;
7
- var _stream = require("stream");
8
7
  var _channelOwner = require("./channelOwner");
9
8
  /**
10
9
  * Copyright (c) Microsoft Corporation.
@@ -30,25 +29,7 @@ class Stream extends _channelOwner.ChannelOwner {
30
29
  super(parent, type, guid, initializer);
31
30
  }
32
31
  stream() {
33
- return new StreamImpl(this._channel);
32
+ return this._platform.streamReadable(this._channel);
34
33
  }
35
34
  }
36
- exports.Stream = Stream;
37
- class StreamImpl extends _stream.Readable {
38
- constructor(channel) {
39
- super();
40
- this._channel = void 0;
41
- this._channel = channel;
42
- }
43
- async _read() {
44
- const result = await this._channel.read({
45
- size: 1024 * 1024
46
- });
47
- if (result.binary.byteLength) this.push(result.binary);else this.push(null);
48
- }
49
- _destroy(error, callback) {
50
- // Stream might be destroyed after the connection was closed.
51
- this._channel.close().catch(e => null);
52
- super._destroy(error, callback);
53
- }
54
- }
35
+ exports.Stream = Stream;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.TimeoutSettings = exports.DEFAULT_TIMEOUT = exports.DEFAULT_LAUNCH_TIMEOUT = void 0;
7
+ /**
8
+ * Copyright 2019 Google Inc. All rights reserved.
9
+ * Modifications 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
+ // Keep in sync with server.
25
+ const DEFAULT_TIMEOUT = exports.DEFAULT_TIMEOUT = 30000;
26
+ const DEFAULT_LAUNCH_TIMEOUT = exports.DEFAULT_LAUNCH_TIMEOUT = 3 * 60 * 1000; // 3 minutes
27
+
28
+ class TimeoutSettings {
29
+ constructor(platform, parent) {
30
+ this._parent = void 0;
31
+ this._defaultTimeout = void 0;
32
+ this._defaultNavigationTimeout = void 0;
33
+ this._platform = void 0;
34
+ this._parent = parent;
35
+ this._platform = platform;
36
+ }
37
+ setDefaultTimeout(timeout) {
38
+ this._defaultTimeout = timeout;
39
+ }
40
+ setDefaultNavigationTimeout(timeout) {
41
+ this._defaultNavigationTimeout = timeout;
42
+ }
43
+ defaultNavigationTimeout() {
44
+ return this._defaultNavigationTimeout;
45
+ }
46
+ defaultTimeout() {
47
+ return this._defaultTimeout;
48
+ }
49
+ navigationTimeout(options) {
50
+ if (typeof options.timeout === 'number') return options.timeout;
51
+ if (this._defaultNavigationTimeout !== undefined) return this._defaultNavigationTimeout;
52
+ if (this._platform.isDebugMode()) return 0;
53
+ if (this._defaultTimeout !== undefined) return this._defaultTimeout;
54
+ if (this._parent) return this._parent.navigationTimeout(options);
55
+ return DEFAULT_TIMEOUT;
56
+ }
57
+ timeout(options) {
58
+ if (typeof options.timeout === 'number') return options.timeout;
59
+ if (this._platform.isDebugMode()) return 0;
60
+ if (this._defaultTimeout !== undefined) return this._defaultTimeout;
61
+ if (this._parent) return this._parent.timeout(options);
62
+ return DEFAULT_TIMEOUT;
63
+ }
64
+ }
65
+ exports.TimeoutSettings = TimeoutSettings;
@@ -70,15 +70,16 @@ class Tracing extends _channelOwner.ChannelOwner {
70
70
  }, false);
71
71
  }
72
72
  async _startCollectingStacks(traceName) {
73
+ var _this$_connection$loc;
73
74
  if (!this._isTracing) {
74
75
  this._isTracing = true;
75
76
  this._connection.setIsTracing(true);
76
77
  }
77
- const result = await this._connection.localUtils()._channel.tracingStarted({
78
+ const result = await ((_this$_connection$loc = this._connection.localUtils()) === null || _this$_connection$loc === void 0 ? void 0 : _this$_connection$loc.tracingStarted({
78
79
  tracesDir: this._tracesDir,
79
80
  traceName
80
- });
81
- this._stacksId = result.stacksId;
81
+ }));
82
+ this._stacksId = result === null || result === void 0 ? void 0 : result.stacksId;
82
83
  }
83
84
  async stopChunk(options = {}) {
84
85
  await this._doStopChunk(options.path);
@@ -94,17 +95,19 @@ class Tracing extends _channelOwner.ChannelOwner {
94
95
  await this._channel.tracingStopChunk({
95
96
  mode: 'discard'
96
97
  });
97
- if (this._stacksId) await this._connection.localUtils()._channel.traceDiscarded({
98
+ if (this._stacksId) await this._connection.localUtils().traceDiscarded({
98
99
  stacksId: this._stacksId
99
100
  });
100
101
  return;
101
102
  }
103
+ const localUtils = this._connection.localUtils();
104
+ if (!localUtils) throw new Error('Cannot save trace in thin clients');
102
105
  const isLocal = !this._connection.isRemote();
103
106
  if (isLocal) {
104
107
  const result = await this._channel.tracingStopChunk({
105
108
  mode: 'entries'
106
109
  });
107
- await this._connection.localUtils()._channel.zip({
110
+ await localUtils.zip({
108
111
  zipFile: filePath,
109
112
  entries: result.entries,
110
113
  mode: 'write',
@@ -119,7 +122,7 @@ class Tracing extends _channelOwner.ChannelOwner {
119
122
 
120
123
  // The artifact may be missing if the browser closed while stopping tracing.
121
124
  if (!result.artifact) {
122
- if (this._stacksId) await this._connection.localUtils()._channel.traceDiscarded({
125
+ if (this._stacksId) await localUtils.traceDiscarded({
123
126
  stacksId: this._stacksId
124
127
  });
125
128
  return;
@@ -129,7 +132,7 @@ class Tracing extends _channelOwner.ChannelOwner {
129
132
  const artifact = _artifact.Artifact.from(result.artifact);
130
133
  await artifact.saveAs(filePath);
131
134
  await artifact.delete();
132
- await this._connection.localUtils()._channel.zip({
135
+ await localUtils.zip({
133
136
  zipFile: filePath,
134
137
  entries: [],
135
138
  mode: 'append',
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.Video = void 0;
7
- var _utils = require("../utils");
7
+ var _manualPromise = require("../utils/isomorphic/manualPromise");
8
8
  /**
9
9
  * Copyright (c) Microsoft Corporation.
10
10
  *
@@ -24,7 +24,7 @@ var _utils = require("../utils");
24
24
  class Video {
25
25
  constructor(page, connection) {
26
26
  this._artifact = null;
27
- this._artifactReadyPromise = new _utils.ManualPromise();
27
+ this._artifactReadyPromise = new _manualPromise.ManualPromise();
28
28
  this._isRemote = false;
29
29
  this._isRemote = connection.isRemote();
30
30
  this._artifact = page._closedOrCrashedScope.safeRace(this._artifactReadyPromise);
@@ -4,9 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.Waiter = void 0;
7
- var _stackTrace = require("../utils/stackTrace");
8
7
  var _errors = require("./errors");
9
- var _utils = require("../utils");
8
+ var _stackTrace = require("../utils/isomorphic/stackTrace");
10
9
  /**
11
10
  * Copyright (c) Microsoft Corporation.
12
11
  *
@@ -33,9 +32,9 @@ class Waiter {
33
32
  this._waitId = void 0;
34
33
  this._error = void 0;
35
34
  this._savedZone = void 0;
36
- this._waitId = (0, _utils.createGuid)();
35
+ this._waitId = channelOwner._platform.createGuid();
37
36
  this._channelOwner = channelOwner;
38
- this._savedZone = _utils.zones.current().without('apiZone');
37
+ this._savedZone = channelOwner._platform.zones.current().pop();
39
38
  this._channelOwner._channel.waitForEventInfo({
40
39
  info: {
41
40
  waitId: this._waitId,
@@ -111,8 +110,8 @@ class Waiter {
111
110
  phase: 'log',
112
111
  message: s
113
112
  }
114
- }).catch(() => {});
115
- }, true);
113
+ });
114
+ }, true).catch(() => {});
116
115
  }
117
116
  _rejectOn(promise, dispose) {
118
117
  this._failures.push(promise);