|
| 1 | +--- a/lib/server/chromium/crDevTools.js |
| 2 | ++++ b/lib/server/chromium/crDevTools.js |
| 3 | +@@ -66,7 +66,11 @@ |
| 4 | + contextId: event.executionContextId |
| 5 | + }).catch(e => null); |
| 6 | + }); |
| 7 | +- Promise.all([session.send('Runtime.enable'), session.send('Runtime.addBinding', { |
| 8 | ++ Promise.all([(() => { |
| 9 | ++ if (process.env['REBROWSER_PATCHES_RUNTIME_FIX_MODE'] === '0') { |
| 10 | ++ return session.send('Runtime.enable', {}); |
| 11 | ++ } |
| 12 | ++ })(), session.send('Runtime.addBinding', { |
| 13 | + name: kBindingName |
| 14 | + }), session.send('Page.enable'), session.send('Page.addScriptToEvaluateOnNewDocument', { |
| 15 | + source: ` |
| 16 | + |
| 17 | +--- a/lib/server/chromium/crPage.js |
| 18 | ++++ b/lib/server/chromium/crPage.js |
| 19 | +@@ -445,7 +445,11 @@ |
| 20 | + } |
| 21 | + }), this._client.send('Log.enable', {}), lifecycleEventsEnabled = this._client.send('Page.setLifecycleEventsEnabled', { |
| 22 | + enabled: true |
| 23 | +- }), this._client.send('Runtime.enable', {}), this._client.send('Runtime.addBinding', { |
| 24 | ++ }), (() => { |
| 25 | ++ if (process.env['REBROWSER_PATCHES_RUNTIME_FIX_MODE'] === '0') { |
| 26 | ++ return this._client.send('Runtime.enable', {}); |
| 27 | ++ } |
| 28 | ++ })(), this._client.send('Runtime.addBinding', { |
| 29 | + name: _page.PageBinding.kPlaywrightBinding |
| 30 | + }), this._client.send('Page.addScriptToEvaluateOnNewDocument', { |
| 31 | + source: '', |
| 32 | +@@ -624,8 +628,11 @@ |
| 33 | + session.once('Runtime.executionContextCreated', async event => { |
| 34 | + worker._createExecutionContext(new _crExecutionContext.CRExecutionContext(session, event.context)); |
| 35 | + }); |
| 36 | +- // This might fail if the target is closed before we initialize. |
| 37 | +- session._sendMayFail('Runtime.enable'); |
| 38 | ++ if (process.env['REBROWSER_PATCHES_RUNTIME_FIX_MODE'] === '0') { |
| 39 | ++ // This might fail if the target is closed before we initialize. |
| 40 | ++ session._sendMayFail('Runtime.enable'); |
| 41 | ++ } |
| 42 | ++ |
| 43 | + // TODO: attribute workers to the right frame. |
| 44 | + this._crPage._networkManager.addSession(session, (_this$_page$_frameMan = this._page._frameManager.frame(this._targetId)) !== null && _this$_page$_frameMan !== void 0 ? _this$_page$_frameMan : undefined).catch(() => {}); |
| 45 | + session._sendMayFail('Runtime.runIfWaitingForDebugger'); |
| 46 | + |
| 47 | +--- a/lib/server/chromium/crServiceWorker.js |
| 48 | ++++ b/lib/server/chromium/crServiceWorker.js |
| 49 | +@@ -46,7 +46,9 @@ |
| 50 | + this.updateOffline(); |
| 51 | + this._networkManager.addSession(session, undefined, true /* isMain */).catch(() => {}); |
| 52 | + } |
| 53 | +- session.send('Runtime.enable', {}).catch(e => {}); |
| 54 | ++ if (process.env['REBROWSER_PATCHES_RUNTIME_FIX_MODE'] === '0') { |
| 55 | ++ session.send('Runtime.enable', {}).catch(e => {}); |
| 56 | ++ } |
| 57 | + session.send('Runtime.runIfWaitingForDebugger').catch(e => {}); |
| 58 | + session.on('Inspector.targetReloadedAfterCrash', () => { |
| 59 | + // Resume service worker after restart. |
| 60 | + |
| 61 | +--- a/lib/server/frames.js |
| 62 | ++++ b/lib/server/frames.js |
| 63 | +@@ -22,6 +22,7 @@ |
| 64 | + var _frameSelectors = require("./frameSelectors"); |
| 65 | + var _errors = require("./errors"); |
| 66 | + var _fileUploadUtils = require("./fileUploadUtils"); |
| 67 | ++var _crExecutionContext = require("./chromium/crExecutionContext"); |
| 68 | + 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); } |
| 69 | + 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; } |
| 70 | + /** |
| 71 | +@@ -60,6 +61,7 @@ |
| 72 | + this._webSockets = new Map(); |
| 73 | + this._openedDialogs = new Set(); |
| 74 | + this._closeAllOpeningDialogs = false; |
| 75 | ++ this._isolatedContext = undefined; |
| 76 | + this._page = page; |
| 77 | + this._mainFrame = undefined; |
| 78 | + } |
| 79 | +@@ -427,6 +429,7 @@ |
| 80 | + if (this._inflightRequests.size === 0) this._startNetworkIdleTimer(); |
| 81 | + this._page.mainFrame()._recalculateNetworkIdle(this); |
| 82 | + this._onLifecycleEvent('commit'); |
| 83 | ++ this._isolatedContext = undefined; |
| 84 | + } |
| 85 | + setPendingDocument(documentInfo) { |
| 86 | + this._pendingDocument = documentInfo; |
| 87 | +@@ -582,6 +585,34 @@ |
| 88 | + return this._page._delegate.getFrameElement(this); |
| 89 | + } |
| 90 | + _context(world) { |
| 91 | ++ if (process.env['REBROWSER_PATCHES_RUNTIME_FIX_MODE'] !== '0') { |
| 92 | ++ // rebrowser-patches: use only utility context, create it on demand and cache |
| 93 | ++ if (this._isolatedContext !== undefined) { |
| 94 | ++ return this._isolatedContext; |
| 95 | ++ } |
| 96 | ++ const utilityWorldName = process.env['REBROWSER_PATCHES_UTILITY_WORLD_NAME'] !== '0' ? process.env['REBROWSER_PATCHES_UTILITY_WORLD_NAME'] || 'util' : '__playwright_utility_world__'; |
| 97 | ++ return this._page._delegate._mainFrameSession._client.send('Page.createIsolatedWorld', { |
| 98 | ++ frameId: this._id, |
| 99 | ++ grantUniveralAccess: true, |
| 100 | ++ worldName: utilityWorldName |
| 101 | ++ }).then(createIsolatedWorldResult => { |
| 102 | ++ const contextPayload = { |
| 103 | ++ id: createIsolatedWorldResult.executionContextId, |
| 104 | ++ name: utilityWorldName, |
| 105 | ++ auxData: { |
| 106 | ++ frameId: this._id, |
| 107 | ++ isDefault: false |
| 108 | ++ } |
| 109 | ++ }; |
| 110 | ++ const delegate = new _crExecutionContext.CRExecutionContext(this._page._delegate._mainFrameSession._client, contextPayload); |
| 111 | ++ this._isolatedContext = new dom.FrameExecutionContext(delegate, this, 'utility'); |
| 112 | ++ return this._isolatedContext; |
| 113 | ++ }).catch(error => { |
| 114 | ++ // probably target is closed |
| 115 | ++ _debugLogger.debugLogger.log('error', error); |
| 116 | ++ console.error('[rebrowser-patches][frames._context] cannot create utility world'); |
| 117 | ++ }); |
| 118 | ++ } |
| 119 | + return this._contextData.get(world).contextPromise.then(contextOrDestroyedReason => { |
| 120 | + if (contextOrDestroyedReason instanceof js.ExecutionContext) return contextOrDestroyedReason; |
| 121 | + throw new Error(contextOrDestroyedReason.destroyedReason); |
0 commit comments