diff --git a/lib/FrameManager.js b/lib/FrameManager.js index 3ff08b8d4b7..3689216709e 100644 --- a/lib/FrameManager.js +++ b/lib/FrameManager.js @@ -182,7 +182,8 @@ class FrameManager extends EventEmitter { _onExecutionContextCreated(contextPayload) { const frameId = contextPayload.auxData && contextPayload.auxData.isDefault ? contextPayload.auxData.frameId : null; const frame = frameId ? this._frames.get(frameId) : null; - const context = new ExecutionContext(this._client, contextPayload, this.createJSHandle.bind(this, contextPayload.id), frame); + /** @type {!ExecutionContext} */ + const context = new ExecutionContext(this._client, contextPayload, obj => this.createJSHandle(context, obj), frame); this._contextIdToContext.set(contextPayload.id, context); if (frame) frame._setDefaultContext(context); @@ -215,12 +216,20 @@ class FrameManager extends EventEmitter { /** * @param {number} contextId + * @return {!ExecutionContext} + */ + executionContextById(contextId) { + const context = this._contextIdToContext.get(contextId); + assert(context, 'INTERNAL ERROR: missing context with id = ' + contextId); + return context; + } + + /** + * @param {!ExecutionContext} context * @param {!Protocol.Runtime.RemoteObject} remoteObject * @return {!JSHandle} */ - createJSHandle(contextId, remoteObject) { - const context = this._contextIdToContext.get(contextId); - assert(context, 'INTERNAL ERROR: missing context with id = ' + contextId); + createJSHandle(context, remoteObject) { if (remoteObject.subtype === 'node') return new ElementHandle(context, this._client, remoteObject, this._page, this); return new JSHandle(context, this._client, remoteObject); diff --git a/lib/Page.js b/lib/Page.js index c9d2df9f7d5..2d01c6a6fa5 100644 --- a/lib/Page.js +++ b/lib/Page.js @@ -477,7 +477,8 @@ class Page extends EventEmitter { * @param {!Protocol.Runtime.consoleAPICalledPayload} event */ async _onConsoleAPI(event) { - const values = event.args.map(arg => this._frameManager.createJSHandle(event.executionContextId, arg)); + const context = this._frameManager.executionContextById(event.executionContextId); + const values = event.args.map(arg => this._frameManager.createJSHandle(context, arg)); this._addConsoleMessage(event.type, values); }