rebrowser-playwright-core 1.47.100 → 1.49.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 (156) hide show
  1. package/README.md +1 -1
  2. package/ThirdPartyNotices.txt +70 -384
  3. package/bin/reinstall_chrome_beta_linux.sh +10 -8
  4. package/bin/reinstall_chrome_stable_linux.sh +10 -8
  5. package/bin/reinstall_msedge_beta_linux.sh +11 -9
  6. package/bin/reinstall_msedge_dev_linux.sh +11 -9
  7. package/bin/reinstall_msedge_stable_linux.sh +11 -9
  8. package/browsers.json +24 -12
  9. package/lib/cli/program.js +49 -19
  10. package/lib/client/api.js +6 -0
  11. package/lib/client/browserContext.js +20 -2
  12. package/lib/client/channelOwner.js +6 -2
  13. package/lib/client/connection.js +3 -0
  14. package/lib/client/fetch.js +16 -21
  15. package/lib/client/jsHandle.js +0 -8
  16. package/lib/client/localUtils.js +1 -0
  17. package/lib/client/locator.js +7 -0
  18. package/lib/client/network.js +180 -17
  19. package/lib/client/page.js +25 -2
  20. package/lib/client/playwright.js +6 -3
  21. package/lib/client/tracing.js +29 -20
  22. package/lib/client/waiter.js +15 -11
  23. package/lib/generated/consoleApiSource.js +1 -1
  24. package/lib/generated/injectedScriptSource.js +1 -1
  25. package/lib/generated/pollingRecorderSource.js +7 -0
  26. package/lib/generated/webSocketMockSource.js +7 -0
  27. package/lib/protocol/validator.js +103 -17
  28. package/lib/server/ariaSnapshot.js +33 -0
  29. package/lib/server/bidi/bidiBrowser.js +23 -8
  30. package/lib/server/bidi/bidiChromium.js +124 -0
  31. package/lib/server/bidi/bidiConnection.js +1 -3
  32. package/lib/server/bidi/bidiExecutionContext.js +0 -6
  33. package/lib/server/bidi/bidiFirefox.js +15 -21
  34. package/lib/server/bidi/bidiInput.js +16 -32
  35. package/lib/server/bidi/bidiNetworkManager.js +39 -5
  36. package/lib/server/bidi/bidiOverCdp.js +103 -0
  37. package/lib/server/bidi/bidiPage.js +98 -25
  38. package/lib/server/bidi/bidiPdf.js +140 -0
  39. package/lib/server/bidi/third_party/firefoxPrefs.js +221 -0
  40. package/lib/server/browser.js +13 -2
  41. package/lib/server/browserContext.js +6 -23
  42. package/lib/server/browserType.js +43 -12
  43. package/lib/server/chromium/chromium.js +9 -17
  44. package/lib/server/chromium/chromiumSwitches.js +3 -1
  45. package/lib/server/chromium/crBrowser.js +4 -3
  46. package/lib/server/chromium/crConnection.js +153 -0
  47. package/lib/server/chromium/crExecutionContext.js +0 -20
  48. package/lib/server/chromium/crPage.js +13 -7
  49. package/lib/server/chromium/videoRecorder.js +1 -1
  50. package/lib/server/codegen/csharp.js +12 -17
  51. package/lib/server/codegen/java.js +5 -8
  52. package/lib/server/codegen/javascript.js +29 -7
  53. package/lib/server/codegen/language.js +14 -2
  54. package/lib/server/codegen/python.js +13 -17
  55. package/lib/server/cookieStore.js +73 -0
  56. package/lib/server/debugController.js +10 -7
  57. package/lib/server/deviceDescriptorsSource.json +127 -127
  58. package/lib/server/dialog.js +1 -0
  59. package/lib/server/dispatchers/androidDispatcher.js +13 -2
  60. package/lib/server/dispatchers/browserContextDispatcher.js +19 -2
  61. package/lib/server/dispatchers/debugControllerDispatcher.js +1 -1
  62. package/lib/server/dispatchers/dispatcher.js +1 -1
  63. package/lib/server/dispatchers/frameDispatcher.js +8 -1
  64. package/lib/server/dispatchers/jsHandleDispatcher.js +0 -5
  65. package/lib/server/dispatchers/pageDispatcher.js +9 -0
  66. package/lib/server/dispatchers/playwrightDispatcher.js +2 -1
  67. package/lib/server/dispatchers/tracingDispatcher.js +10 -0
  68. package/lib/server/dispatchers/webSocketRouteDispatcher.js +189 -0
  69. package/lib/server/dom.js +79 -36
  70. package/lib/server/download.js +9 -2
  71. package/lib/server/fetch.js +105 -96
  72. package/lib/server/firefox/ffBrowser.js +6 -4
  73. package/lib/server/firefox/ffExecutionContext.js +0 -15
  74. package/lib/server/firefox/ffNetworkManager.js +1 -1
  75. package/lib/server/firefox/ffPage.js +6 -3
  76. package/lib/server/firefox/firefox.js +2 -13
  77. package/lib/server/frameSelectors.js +1 -1
  78. package/lib/server/frames.js +68 -67
  79. package/lib/server/har/harTracer.js +11 -0
  80. package/lib/server/index.js +0 -6
  81. package/lib/server/input.js +0 -1
  82. package/lib/server/javascript.js +0 -13
  83. package/lib/server/page.js +53 -9
  84. package/lib/server/playwright.js +5 -2
  85. package/lib/server/progress.js +0 -3
  86. package/lib/server/recorder/contextRecorder.js +33 -50
  87. package/lib/server/recorder/recorderApp.js +22 -25
  88. package/lib/server/recorder/recorderCollection.js +68 -79
  89. package/lib/server/recorder/recorderInTraceViewer.js +144 -0
  90. package/lib/server/recorder/recorderRunner.js +75 -97
  91. package/lib/server/recorder/recorderUtils.js +48 -6
  92. package/lib/server/recorder.js +87 -47
  93. package/lib/server/registry/index.js +154 -26
  94. package/lib/server/registry/nativeDeps.js +6 -3
  95. package/lib/server/socksClientCertificatesInterceptor.js +15 -3
  96. package/lib/server/trace/recorder/snapshotter.js +2 -12
  97. package/lib/server/trace/recorder/snapshotterInjected.js +21 -3
  98. package/lib/server/trace/recorder/tracing.js +127 -17
  99. package/lib/server/trace/test/inMemorySnapshotter.js +4 -4
  100. package/lib/server/trace/viewer/traceViewer.js +4 -6
  101. package/lib/server/webkit/webkit.js +1 -1
  102. package/lib/server/webkit/wkBrowser.js +8 -7
  103. package/lib/server/webkit/wkExecutionContext.js +0 -16
  104. package/lib/server/webkit/wkPage.js +11 -4
  105. package/lib/utils/comparators.js +12 -30
  106. package/lib/utils/crypto.js +1 -4
  107. package/lib/utils/happy-eyeballs.js +13 -0
  108. package/lib/utils/hostPlatform.js +8 -2
  109. package/lib/utils/httpServer.js +1 -0
  110. package/lib/utils/isomorphic/ariaSnapshot.js +267 -0
  111. package/lib/utils/isomorphic/locatorGenerators.js +30 -21
  112. package/lib/utils/isomorphic/locatorParser.js +2 -2
  113. package/lib/utils/isomorphic/recorderUtils.js +227 -0
  114. package/lib/utils/isomorphic/stringUtils.js +30 -0
  115. package/lib/utils/isomorphic/urlMatch.js +5 -1
  116. package/lib/utils/network.js +1 -1
  117. package/lib/utils/sequence.js +64 -0
  118. package/lib/utils/stackTrace.js +16 -3
  119. package/lib/utils/zones.js +32 -23
  120. package/lib/utilsBundle.js +4 -5
  121. package/lib/utilsBundleImpl/index.js +190 -33
  122. package/lib/vite/htmlReport/index.html +19 -16
  123. package/lib/vite/recorder/assets/codeMirrorModule-AFvV6hAs.js +24 -0
  124. package/lib/vite/recorder/assets/index-_cTWgVuJ.js +184 -0
  125. package/lib/vite/recorder/assets/{index-B-MT5gKo.css → index-iA1aAGZg.css} +1 -1
  126. package/lib/vite/recorder/index.html +2 -2
  127. package/lib/vite/traceViewer/assets/codeMirrorModule-KatbITLF.js +24 -0
  128. package/lib/vite/traceViewer/assets/inspectorTab-DdpLd2bb.js +68 -0
  129. package/lib/vite/traceViewer/assets/workbench-CdYbzWFD.js +9 -0
  130. package/lib/vite/traceViewer/embedded.6m3UZh7r.js +2 -0
  131. package/lib/vite/traceViewer/embedded.html +5 -3
  132. package/lib/vite/traceViewer/index.WUV-8boJ.js +2 -0
  133. package/lib/vite/traceViewer/index.html +24 -5
  134. package/lib/vite/traceViewer/inspectorTab.DEOUW62d.css +1 -0
  135. package/lib/vite/traceViewer/recorder.B_SY1GJM.css +0 -0
  136. package/lib/vite/traceViewer/recorder.OT2tVHgn.js +2 -0
  137. package/lib/vite/traceViewer/recorder.html +17 -0
  138. package/lib/vite/traceViewer/sw.bundle.js +3 -3
  139. package/lib/vite/traceViewer/uiMode.BZBTyvGn.js +5 -0
  140. package/lib/vite/traceViewer/uiMode.html +6 -4
  141. package/lib/vite/traceViewer/{uiMode.D3cNFP6u.css → uiMode.voC1ZiOQ.css} +1 -1
  142. package/lib/vite/traceViewer/workbench.C-zR9ysA.css +1 -0
  143. package/package.json +1 -1
  144. package/types/protocol.d.ts +135 -16
  145. package/types/types.d.ts +2149 -965
  146. package/lib/generated/recorderSource.js +0 -7
  147. package/lib/third_party/diff_match_patch.js +0 -2222
  148. package/lib/vite/recorder/assets/codeMirrorModule-aW6Vz3gf.js +0 -24
  149. package/lib/vite/recorder/assets/index-DCpXOVIh.js +0 -47
  150. package/lib/vite/traceViewer/assets/codeMirrorModule-eFKCUIu2.js +0 -24
  151. package/lib/vite/traceViewer/assets/workbench-D0cirtfA.js +0 -72
  152. package/lib/vite/traceViewer/embedded.BkuvsLJp.js +0 -2
  153. package/lib/vite/traceViewer/index.C968kAiC.js +0 -2
  154. package/lib/vite/traceViewer/uiMode.BkFnr4V0.js +0 -10
  155. package/lib/vite/traceViewer/workbench.DjbIuxix.css +0 -1
  156. /package/lib/server/recorder/{recorderActions.js → recorderFrontend.js} +0 -0
@@ -14,6 +14,7 @@ var bidi = _interopRequireWildcard(require("./third_party/bidiProtocol"));
14
14
  var _bidiExecutionContext = require("./bidiExecutionContext");
15
15
  var _bidiNetworkManager = require("./bidiNetworkManager");
16
16
  var _browserContext = require("../browserContext");
17
+ var _bidiPdf = require("./bidiPdf");
17
18
  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); }
18
19
  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; }
19
20
  /**
@@ -33,6 +34,7 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
33
34
  */
34
35
 
35
36
  const UTILITY_WORLD_NAME = '__playwright_utility_world__';
37
+ const kPlaywrightBindingChannel = 'playwrightChannel';
36
38
  class BidiPage {
37
39
  constructor(browserContext, bidiSession, opener) {
38
40
  this.rawMouse = void 0;
@@ -46,7 +48,9 @@ class BidiPage {
46
48
  this._sessionListeners = [];
47
49
  this._browserContext = void 0;
48
50
  this._networkManager = void 0;
51
+ this._pdf = void 0;
49
52
  this._initializedPage = null;
53
+ this._initScriptIds = [];
50
54
  this._session = bidiSession;
51
55
  this._opener = opener;
52
56
  this.rawKeyboard = new _bidiInput.RawKeyboardImpl(bidiSession);
@@ -56,8 +60,9 @@ class BidiPage {
56
60
  this._page = new _page.Page(this, browserContext);
57
61
  this._browserContext = browserContext;
58
62
  this._networkManager = new _bidiNetworkManager.BidiNetworkManager(this._session, this._page, this._onNavigationResponseStarted.bind(this));
63
+ this._pdf = new _bidiPdf.BidiPDF(this._session);
59
64
  this._page.on(_page.Page.Events.FrameDetached, frame => this._removeContextsForFrame(frame, false));
60
- this._sessionListeners = [_eventsHelper.eventsHelper.addEventListener(bidiSession, 'script.realmCreated', this._onRealmCreated.bind(this)), _eventsHelper.eventsHelper.addEventListener(bidiSession, 'browsingContext.contextDestroyed', this._onBrowsingContextDestroyed.bind(this)), _eventsHelper.eventsHelper.addEventListener(bidiSession, 'browsingContext.navigationStarted', this._onNavigationStarted.bind(this)), _eventsHelper.eventsHelper.addEventListener(bidiSession, 'browsingContext.navigationAborted', this._onNavigationAborted.bind(this)), _eventsHelper.eventsHelper.addEventListener(bidiSession, 'browsingContext.navigationFailed', this._onNavigationFailed.bind(this)), _eventsHelper.eventsHelper.addEventListener(bidiSession, 'browsingContext.fragmentNavigated', this._onFragmentNavigated.bind(this)), _eventsHelper.eventsHelper.addEventListener(bidiSession, 'browsingContext.domContentLoaded', this._onDomContentLoaded.bind(this)), _eventsHelper.eventsHelper.addEventListener(bidiSession, 'browsingContext.load', this._onLoad.bind(this)), _eventsHelper.eventsHelper.addEventListener(bidiSession, 'browsingContext.userPromptOpened', this._onUserPromptOpened.bind(this)), _eventsHelper.eventsHelper.addEventListener(bidiSession, 'log.entryAdded', this._onLogEntryAdded.bind(this))];
65
+ this._sessionListeners = [_eventsHelper.eventsHelper.addEventListener(bidiSession, 'script.realmCreated', this._onRealmCreated.bind(this)), _eventsHelper.eventsHelper.addEventListener(bidiSession, 'script.message', this._onScriptMessage.bind(this)), _eventsHelper.eventsHelper.addEventListener(bidiSession, 'browsingContext.contextDestroyed', this._onBrowsingContextDestroyed.bind(this)), _eventsHelper.eventsHelper.addEventListener(bidiSession, 'browsingContext.navigationStarted', this._onNavigationStarted.bind(this)), _eventsHelper.eventsHelper.addEventListener(bidiSession, 'browsingContext.navigationAborted', this._onNavigationAborted.bind(this)), _eventsHelper.eventsHelper.addEventListener(bidiSession, 'browsingContext.navigationFailed', this._onNavigationFailed.bind(this)), _eventsHelper.eventsHelper.addEventListener(bidiSession, 'browsingContext.fragmentNavigated', this._onFragmentNavigated.bind(this)), _eventsHelper.eventsHelper.addEventListener(bidiSession, 'browsingContext.domContentLoaded', this._onDomContentLoaded.bind(this)), _eventsHelper.eventsHelper.addEventListener(bidiSession, 'browsingContext.load', this._onLoad.bind(this)), _eventsHelper.eventsHelper.addEventListener(bidiSession, 'browsingContext.userPromptOpened', this._onUserPromptOpened.bind(this)), _eventsHelper.eventsHelper.addEventListener(bidiSession, 'log.entryAdded', this._onLogEntryAdded.bind(this))];
61
66
 
62
67
  // Initialize main frame.
63
68
  this._pagePromise = this._initialize().finally(async () => {
@@ -72,18 +77,12 @@ class BidiPage {
72
77
  });
73
78
  }
74
79
  async _initialize() {
75
- const {
76
- contexts
77
- } = await this._session.send('browsingContext.getTree', {
78
- root: this._session.sessionId
79
- });
80
- this._handleFrameTree(contexts[0]);
81
- await Promise.all([this.updateHttpCredentials(), this.updateRequestInterception(), this._updateViewport()]);
80
+ // Initialize main frame.
81
+ this._onFrameAttached(this._session.sessionId, null);
82
+ await Promise.all([this.updateHttpCredentials(), this.updateRequestInterception(), this._updateViewport(), this._installMainBinding(), this._addAllInitScripts()]);
82
83
  }
83
- _handleFrameTree(frameTree) {
84
- this._onFrameAttached(frameTree.context, frameTree.parent || null);
85
- if (!frameTree.children) return;
86
- for (const child of frameTree.children) this._handleFrameTree(child);
84
+ async _addAllInitScripts() {
85
+ return Promise.all(this._page.allInitScripts().map(initScript => this.addInitScript(initScript)));
87
86
  }
88
87
  potentiallyUninitializedPage() {
89
88
  return this._page;
@@ -236,7 +235,11 @@ class BidiPage {
236
235
  await this._updateViewport();
237
236
  }
238
237
  async updateUserAgent() {}
239
- async bringToFront() {}
238
+ async bringToFront() {
239
+ await this._session.send('browsingContext.activate', {
240
+ context: this._session.sessionId
241
+ });
242
+ }
240
243
  async _updateViewport() {
241
244
  const options = this._browserContext._options;
242
245
  const deviceSize = this._page.emulatedSize();
@@ -266,20 +269,72 @@ class BidiPage {
266
269
  wait: bidi.BrowsingContext.ReadinessState.Interactive
267
270
  });
268
271
  }
269
- goBack() {
270
- throw new Error('Method not implemented.');
272
+ async goBack() {
273
+ return await this._session.send('browsingContext.traverseHistory', {
274
+ context: this._session.sessionId,
275
+ delta: -1
276
+ }).then(() => true).catch(() => false);
277
+ }
278
+ async goForward() {
279
+ return await this._session.send('browsingContext.traverseHistory', {
280
+ context: this._session.sessionId,
281
+ delta: +1
282
+ }).then(() => true).catch(() => false);
271
283
  }
272
- goForward() {
284
+ async requestGC() {
273
285
  throw new Error('Method not implemented.');
274
286
  }
287
+
288
+ // TODO: consider calling this only when bindings are added.
289
+ async _installMainBinding() {
290
+ const functionDeclaration = addMainBinding.toString();
291
+ const args = [{
292
+ type: 'channel',
293
+ value: {
294
+ channel: kPlaywrightBindingChannel,
295
+ ownership: bidi.Script.ResultOwnership.Root
296
+ }
297
+ }];
298
+ const promises = [];
299
+ promises.push(this._session.send('script.addPreloadScript', {
300
+ functionDeclaration,
301
+ arguments: args
302
+ }));
303
+ promises.push(this._session.send('script.callFunction', {
304
+ functionDeclaration,
305
+ arguments: args,
306
+ target: toBidiExecutionContext(await this._page.mainFrame()._mainContext())._target,
307
+ awaitPromise: false,
308
+ userActivation: false
309
+ }));
310
+ await Promise.all(promises);
311
+ }
312
+ async _onScriptMessage(event) {
313
+ if (event.channel !== kPlaywrightBindingChannel) return;
314
+ const pageOrError = await this.pageOrError();
315
+ if (pageOrError instanceof Error) return;
316
+ const context = this._realmToContext.get(event.source.realm);
317
+ if (!context) return;
318
+ if (event.data.type !== 'string') return;
319
+ await this._page._onBindingCalled(event.data.value, context);
320
+ }
275
321
  async addInitScript(initScript) {
276
- await this._updateBootstrapScript();
322
+ const {
323
+ script
324
+ } = await this._session.send('script.addPreloadScript', {
325
+ // TODO: remove function call from the source.
326
+ functionDeclaration: `() => { return ${initScript.source} }`,
327
+ // TODO: push to iframes?
328
+ contexts: [this._session.sessionId]
329
+ });
330
+ if (!initScript.internal) this._initScriptIds.push(script);
277
331
  }
278
332
  async removeNonInternalInitScripts() {
279
- await this._updateBootstrapScript();
280
- }
281
- async _updateBootstrapScript() {
282
- throw new Error('Method not implemented.');
333
+ const promises = this._initScriptIds.map(script => this._session.send('script.removePreloadScript', {
334
+ script
335
+ }));
336
+ this._initScriptIds = [];
337
+ await Promise.all(promises);
283
338
  }
284
339
  async closePage(runBeforeUnload) {
285
340
  await this._session.send('browsingContext.close', {
@@ -289,7 +344,22 @@ class BidiPage {
289
344
  }
290
345
  async setBackgroundColor(color) {}
291
346
  async takeScreenshot(progress, format, documentRect, viewportRect, quality, fitsViewport, scale) {
292
- throw new Error('Method not implemented.');
347
+ const rect = documentRect || viewportRect;
348
+ const {
349
+ data
350
+ } = await this._session.send('browsingContext.captureScreenshot', {
351
+ context: this._session.sessionId,
352
+ format: {
353
+ type: `image/${format === 'png' ? 'png' : 'jpeg'}`,
354
+ quality: quality || 80
355
+ },
356
+ origin: documentRect ? 'document' : 'viewport',
357
+ clip: {
358
+ type: 'box',
359
+ ...rect
360
+ }
361
+ });
362
+ return Buffer.from(data, 'base64');
293
363
  }
294
364
  async getContentFrame(handle) {
295
365
  const executionContext = toBidiExecutionContext(handle._context);
@@ -419,6 +489,9 @@ class BidiPage {
419
489
  }
420
490
  async inputActionEpilogue() {}
421
491
  async resetForReuse() {}
492
+ async pdf(options) {
493
+ return this._pdf.generate(options);
494
+ }
422
495
  async getFrameElement(frame) {
423
496
  const parent = frame.parentFrame();
424
497
  if (!parent) throw new Error('Frame has been detached.');
@@ -445,11 +518,11 @@ class BidiPage {
445
518
  shouldToggleStyleSheetToSyncAnimations() {
446
519
  return true;
447
520
  }
448
- useMainWorldForSetContent() {
449
- return true;
450
- }
451
521
  }
452
522
  exports.BidiPage = BidiPage;
523
+ function addMainBinding(callback) {
524
+ globalThis['__playwright__binding__'] = callback;
525
+ }
453
526
  function toBidiExecutionContext(executionContext) {
454
527
  return executionContext[contextDelegateSymbol];
455
528
  }
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.BidiPDF = void 0;
7
+ var _utils = require("../../utils");
8
+ /**
9
+ * Copyright 2017 Google Inc. All rights reserved.
10
+ * Modifications copyright (c) Microsoft Corporation.
11
+ *
12
+ * Licensed under the Apache License, Version 2.0 (the "License");
13
+ * you may not use this file except in compliance with the License.
14
+ * You may obtain a copy of the License at
15
+ *
16
+ * http://www.apache.org/licenses/LICENSE-2.0
17
+ *
18
+ * Unless required by applicable law or agreed to in writing, software
19
+ * distributed under the License is distributed on an "AS IS" BASIS,
20
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
+ * See the License for the specific language governing permissions and
22
+ * limitations under the License.
23
+ */
24
+
25
+ const PagePaperFormats = {
26
+ letter: {
27
+ width: 8.5,
28
+ height: 11
29
+ },
30
+ legal: {
31
+ width: 8.5,
32
+ height: 14
33
+ },
34
+ tabloid: {
35
+ width: 11,
36
+ height: 17
37
+ },
38
+ ledger: {
39
+ width: 17,
40
+ height: 11
41
+ },
42
+ a0: {
43
+ width: 33.1,
44
+ height: 46.8
45
+ },
46
+ a1: {
47
+ width: 23.4,
48
+ height: 33.1
49
+ },
50
+ a2: {
51
+ width: 16.54,
52
+ height: 23.4
53
+ },
54
+ a3: {
55
+ width: 11.7,
56
+ height: 16.54
57
+ },
58
+ a4: {
59
+ width: 8.27,
60
+ height: 11.7
61
+ },
62
+ a5: {
63
+ width: 5.83,
64
+ height: 8.27
65
+ },
66
+ a6: {
67
+ width: 4.13,
68
+ height: 5.83
69
+ }
70
+ };
71
+ const unitToPixels = {
72
+ 'px': 1,
73
+ 'in': 96,
74
+ 'cm': 37.8,
75
+ 'mm': 3.78
76
+ };
77
+ function convertPrintParameterToInches(text) {
78
+ if (text === undefined) return undefined;
79
+ let unit = text.substring(text.length - 2).toLowerCase();
80
+ let valueText = '';
81
+ if (unitToPixels.hasOwnProperty(unit)) {
82
+ valueText = text.substring(0, text.length - 2);
83
+ } else {
84
+ // In case of unknown unit try to parse the whole parameter as number of pixels.
85
+ // This is consistent with phantom's paperSize behavior.
86
+ unit = 'px';
87
+ valueText = text;
88
+ }
89
+ const value = Number(valueText);
90
+ (0, _utils.assert)(!isNaN(value), 'Failed to parse parameter value: ' + text);
91
+ const pixels = value * unitToPixels[unit];
92
+ return pixels / 96;
93
+ }
94
+ class BidiPDF {
95
+ constructor(session) {
96
+ this._session = void 0;
97
+ this._session = session;
98
+ }
99
+ async generate(options) {
100
+ const {
101
+ scale = 1,
102
+ printBackground = false,
103
+ landscape = false,
104
+ pageRanges = '',
105
+ margin = {}
106
+ } = options;
107
+ let paperWidth = 8.5;
108
+ let paperHeight = 11;
109
+ if (options.format) {
110
+ const format = PagePaperFormats[options.format.toLowerCase()];
111
+ (0, _utils.assert)(format, 'Unknown paper format: ' + options.format);
112
+ paperWidth = format.width;
113
+ paperHeight = format.height;
114
+ } else {
115
+ paperWidth = convertPrintParameterToInches(options.width) || paperWidth;
116
+ paperHeight = convertPrintParameterToInches(options.height) || paperHeight;
117
+ }
118
+ const {
119
+ data
120
+ } = await this._session.send('browsingContext.print', {
121
+ context: this._session.sessionId,
122
+ background: printBackground,
123
+ margin: {
124
+ bottom: convertPrintParameterToInches(margin.bottom) || 0,
125
+ left: convertPrintParameterToInches(margin.left) || 0,
126
+ right: convertPrintParameterToInches(margin.right) || 0,
127
+ top: convertPrintParameterToInches(margin.top) || 0
128
+ },
129
+ orientation: landscape ? 'landscape' : 'portrait',
130
+ page: {
131
+ width: paperWidth,
132
+ height: paperHeight
133
+ },
134
+ pageRanges: pageRanges ? pageRanges.split(',').map(r => r.trim()) : undefined,
135
+ scale
136
+ });
137
+ return Buffer.from(data, 'base64');
138
+ }
139
+ }
140
+ exports.BidiPDF = BidiPDF;
@@ -0,0 +1,221 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createProfile = createProfile;
7
+ var _fs = _interopRequireDefault(require("fs"));
8
+ var _path = _interopRequireDefault(require("path"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ /**
11
+ * @license
12
+ * Copyright 2023 Google Inc.
13
+ * SPDX-License-Identifier: Apache-2.0
14
+ */
15
+
16
+ /* eslint-disable curly, indent */
17
+
18
+ async function createProfile(options) {
19
+ if (!_fs.default.existsSync(options.path)) {
20
+ await _fs.default.promises.mkdir(options.path, {
21
+ recursive: true
22
+ });
23
+ }
24
+ await writePreferences({
25
+ preferences: {
26
+ ...defaultProfilePreferences(options.preferences),
27
+ ...options.preferences
28
+ },
29
+ path: options.path
30
+ });
31
+ }
32
+ function defaultProfilePreferences(extraPrefs) {
33
+ const server = 'dummy.test';
34
+ const defaultPrefs = {
35
+ // Make sure Shield doesn't hit the network.
36
+ 'app.normandy.api_url': '',
37
+ // Disable Firefox old build background check
38
+ 'app.update.checkInstallTime': false,
39
+ // Disable automatically upgrading Firefox
40
+ 'app.update.disabledForTesting': true,
41
+ // Increase the APZ content response timeout to 1 minute
42
+ 'apz.content_response_timeout': 60000,
43
+ // Prevent various error message on the console
44
+ // jest-puppeteer asserts that no error message is emitted by the console
45
+ 'browser.contentblocking.features.standard': '-tp,tpPrivate,cookieBehavior0,-cm,-fp',
46
+ // Enable the dump function: which sends messages to the system
47
+ // console
48
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=1543115
49
+ 'browser.dom.window.dump.enabled': true,
50
+ // Disable topstories
51
+ 'browser.newtabpage.activity-stream.feeds.system.topstories': false,
52
+ // Always display a blank page
53
+ 'browser.newtabpage.enabled': false,
54
+ // Background thumbnails in particular cause grief: and disabling
55
+ // thumbnails in general cannot hurt
56
+ 'browser.pagethumbnails.capturing_disabled': true,
57
+ // Disable safebrowsing components.
58
+ 'browser.safebrowsing.blockedURIs.enabled': false,
59
+ 'browser.safebrowsing.downloads.enabled': false,
60
+ 'browser.safebrowsing.malware.enabled': false,
61
+ 'browser.safebrowsing.phishing.enabled': false,
62
+ // Disable updates to search engines.
63
+ 'browser.search.update': false,
64
+ // Do not restore the last open set of tabs if the browser has crashed
65
+ 'browser.sessionstore.resume_from_crash': false,
66
+ // Skip check for default browser on startup
67
+ 'browser.shell.checkDefaultBrowser': false,
68
+ // Disable newtabpage
69
+ 'browser.startup.homepage': 'about:blank',
70
+ // Do not redirect user when a milstone upgrade of Firefox is detected
71
+ 'browser.startup.homepage_override.mstone': 'ignore',
72
+ // Start with a blank page about:blank
73
+ 'browser.startup.page': 0,
74
+ // Do not allow background tabs to be zombified on Android: otherwise for
75
+ // tests that open additional tabs: the test harness tab itself might get
76
+ // unloaded
77
+ 'browser.tabs.disableBackgroundZombification': false,
78
+ // Do not warn when closing all other open tabs
79
+ 'browser.tabs.warnOnCloseOtherTabs': false,
80
+ // Do not warn when multiple tabs will be opened
81
+ 'browser.tabs.warnOnOpen': false,
82
+ // Do not automatically offer translations, as tests do not expect this.
83
+ 'browser.translations.automaticallyPopup': false,
84
+ // Disable the UI tour.
85
+ 'browser.uitour.enabled': false,
86
+ // Turn off search suggestions in the location bar so as not to trigger
87
+ // network connections.
88
+ 'browser.urlbar.suggest.searches': false,
89
+ // Disable first run splash page on Windows 10
90
+ 'browser.usedOnWindows10.introURL': '',
91
+ // Do not warn on quitting Firefox
92
+ 'browser.warnOnQuit': false,
93
+ // Defensively disable data reporting systems
94
+ 'datareporting.healthreport.documentServerURI': `http://${server}/dummy/healthreport/`,
95
+ 'datareporting.healthreport.logging.consoleEnabled': false,
96
+ 'datareporting.healthreport.service.enabled': false,
97
+ 'datareporting.healthreport.service.firstRun': false,
98
+ 'datareporting.healthreport.uploadEnabled': false,
99
+ // Do not show datareporting policy notifications which can interfere with tests
100
+ 'datareporting.policy.dataSubmissionEnabled': false,
101
+ 'datareporting.policy.dataSubmissionPolicyBypassNotification': true,
102
+ // DevTools JSONViewer sometimes fails to load dependencies with its require.js.
103
+ // This doesn't affect Puppeteer but spams console (Bug 1424372)
104
+ 'devtools.jsonview.enabled': false,
105
+ // Disable popup-blocker
106
+ 'dom.disable_open_during_load': false,
107
+ // Enable the support for File object creation in the content process
108
+ // Required for |Page.setFileInputFiles| protocol method.
109
+ 'dom.file.createInChild': true,
110
+ // Disable the ProcessHangMonitor
111
+ 'dom.ipc.reportProcessHangs': false,
112
+ // Disable slow script dialogues
113
+ 'dom.max_chrome_script_run_time': 0,
114
+ 'dom.max_script_run_time': 0,
115
+ // Only load extensions from the application and user profile
116
+ // AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_APPLICATION
117
+ 'extensions.autoDisableScopes': 0,
118
+ 'extensions.enabledScopes': 5,
119
+ // Disable metadata caching for installed add-ons by default
120
+ 'extensions.getAddons.cache.enabled': false,
121
+ // Disable installing any distribution extensions or add-ons.
122
+ 'extensions.installDistroAddons': false,
123
+ // Disabled screenshots extension
124
+ 'extensions.screenshots.disabled': true,
125
+ // Turn off extension updates so they do not bother tests
126
+ 'extensions.update.enabled': false,
127
+ // Turn off extension updates so they do not bother tests
128
+ 'extensions.update.notifyUser': false,
129
+ // Make sure opening about:addons will not hit the network
130
+ 'extensions.webservice.discoverURL': `http://${server}/dummy/discoveryURL`,
131
+ // Allow the application to have focus even it runs in the background
132
+ 'focusmanager.testmode': true,
133
+ // Disable useragent updates
134
+ 'general.useragent.updates.enabled': false,
135
+ // Always use network provider for geolocation tests so we bypass the
136
+ // macOS dialog raised by the corelocation provider
137
+ 'geo.provider.testing': true,
138
+ // Do not scan Wifi
139
+ 'geo.wifi.scan': false,
140
+ // No hang monitor
141
+ 'hangmonitor.timeout': 0,
142
+ // Show chrome errors and warnings in the error console
143
+ 'javascript.options.showInConsole': true,
144
+ // Disable download and usage of OpenH264: and Widevine plugins
145
+ 'media.gmp-manager.updateEnabled': false,
146
+ // Disable the GFX sanity window
147
+ 'media.sanity-test.disabled': true,
148
+ // Disable experimental feature that is only available in Nightly
149
+ 'network.cookie.sameSite.laxByDefault': false,
150
+ // Do not prompt for temporary redirects
151
+ 'network.http.prompt-temp-redirect': false,
152
+ // Disable speculative connections so they are not reported as leaking
153
+ // when they are hanging around
154
+ 'network.http.speculative-parallel-limit': 0,
155
+ // Do not automatically switch between offline and online
156
+ 'network.manage-offline-status': false,
157
+ // Make sure SNTP requests do not hit the network
158
+ 'network.sntp.pools': server,
159
+ // Disable Flash.
160
+ 'plugin.state.flash': 0,
161
+ 'privacy.trackingprotection.enabled': false,
162
+ // Can be removed once Firefox 89 is no longer supported
163
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=1710839
164
+ 'remote.enabled': true,
165
+ // Don't do network connections for mitm priming
166
+ 'security.certerrors.mitm.priming.enabled': false,
167
+ // Local documents have access to all other local documents,
168
+ // including directory listings
169
+ 'security.fileuri.strict_origin_policy': false,
170
+ // Do not wait for the notification button security delay
171
+ 'security.notification_enable_delay': 0,
172
+ // Ensure blocklist updates do not hit the network
173
+ 'services.settings.server': `http://${server}/dummy/blocklist/`,
174
+ // Do not automatically fill sign-in forms with known usernames and
175
+ // passwords
176
+ 'signon.autofillForms': false,
177
+ // Disable password capture, so that tests that include forms are not
178
+ // influenced by the presence of the persistent doorhanger notification
179
+ 'signon.rememberSignons': false,
180
+ // Disable first-run welcome page
181
+ 'startup.homepage_welcome_url': 'about:blank',
182
+ // Disable first-run welcome page
183
+ 'startup.homepage_welcome_url.additional': '',
184
+ // Disable browser animations (tabs, fullscreen, sliding alerts)
185
+ 'toolkit.cosmeticAnimations.enabled': false,
186
+ // Prevent starting into safe mode after application crashes
187
+ 'toolkit.startup.max_resumed_crashes': -1
188
+ };
189
+ return Object.assign(defaultPrefs, extraPrefs);
190
+ }
191
+
192
+ /**
193
+ * Populates the user.js file with custom preferences as needed to allow
194
+ * Firefox's CDP support to properly function. These preferences will be
195
+ * automatically copied over to prefs.js during startup of Firefox. To be
196
+ * able to restore the original values of preferences a backup of prefs.js
197
+ * will be created.
198
+ *
199
+ * @param prefs - List of preferences to add.
200
+ * @param profilePath - Firefox profile to write the preferences to.
201
+ */
202
+ async function writePreferences(options) {
203
+ const prefsPath = _path.default.join(options.path, 'prefs.js');
204
+ const lines = Object.entries(options.preferences).map(([key, value]) => {
205
+ return `user_pref(${JSON.stringify(key)}, ${JSON.stringify(value)});`;
206
+ });
207
+
208
+ // Use allSettled to prevent corruption
209
+ const result = await Promise.allSettled([_fs.default.promises.writeFile(_path.default.join(options.path, 'user.js'), lines.join('\n')),
210
+ // Create a backup of the preferences file if it already exitsts.
211
+ _fs.default.promises.access(prefsPath, _fs.default.constants.F_OK).then(async () => {
212
+ await _fs.default.promises.copyFile(prefsPath, _path.default.join(options.path, 'prefs.js.playwright'));
213
+ },
214
+ // Swallow only if file does not exist
215
+ () => {})]);
216
+ for (const command of result) {
217
+ if (command.status === 'rejected') {
218
+ throw command.reason;
219
+ }
220
+ }
221
+ }
@@ -9,6 +9,7 @@ var _page = require("./page");
9
9
  var _download = require("./download");
10
10
  var _instrumentation = require("./instrumentation");
11
11
  var _artifact = require("./artifact");
12
+ var _socksClientCertificatesInterceptor = require("./socksClientCertificatesInterceptor");
12
13
  /**
13
14
  * Copyright (c) Microsoft Corporation.
14
15
  *
@@ -41,13 +42,23 @@ class Browser extends _instrumentation.SdkObject {
41
42
  this.instrumentation.onBrowserOpen(this);
42
43
  }
43
44
  async newContext(metadata, options) {
45
+ var _options$clientCertif;
44
46
  (0, _browserContext.validateBrowserContextOptions)(options, this.options);
45
- const clientCertificatesProxy = await (0, _browserContext.createClientCertificatesProxyIfNeeded)(options, this.options);
47
+ let clientCertificatesProxy;
48
+ if ((_options$clientCertif = options.clientCertificates) !== null && _options$clientCertif !== void 0 && _options$clientCertif.length) {
49
+ clientCertificatesProxy = new _socksClientCertificatesInterceptor.ClientCertificatesProxy(options);
50
+ options = {
51
+ ...options
52
+ };
53
+ options.proxyOverride = await clientCertificatesProxy.listen();
54
+ options.internalIgnoreHTTPSErrors = true;
55
+ }
46
56
  let context;
47
57
  try {
48
58
  context = await this.doCreateNewContext(options);
49
59
  } catch (error) {
50
- await (clientCertificatesProxy === null || clientCertificatesProxy === void 0 ? void 0 : clientCertificatesProxy.close());
60
+ var _clientCertificatesPr;
61
+ await ((_clientCertificatesPr = clientCertificatesProxy) === null || _clientCertificatesPr === void 0 ? void 0 : _clientCertificatesPr.close());
51
62
  throw error;
52
63
  }
53
64
  context._clientCertificatesProxy = clientCertificatesProxy;