mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
refactor: move createCdpHandle to IsolatedWorld (#12397)
This commit is contained in:
parent
857051212c
commit
5ce4f12960
@ -268,7 +268,7 @@ export class ExecutionContext {
|
|||||||
|
|
||||||
return returnByValue
|
return returnByValue
|
||||||
? valueFromRemoteObject(remoteObject)
|
? valueFromRemoteObject(remoteObject)
|
||||||
: createCdpHandle(this._world, remoteObject);
|
: this._world.createCdpHandle(remoteObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
const functionDeclaration = stringifyFunction(pageFunction);
|
const functionDeclaration = stringifyFunction(pageFunction);
|
||||||
@ -305,7 +305,7 @@ export class ExecutionContext {
|
|||||||
}
|
}
|
||||||
return returnByValue
|
return returnByValue
|
||||||
? valueFromRemoteObject(remoteObject)
|
? valueFromRemoteObject(remoteObject)
|
||||||
: createCdpHandle(this._world, remoteObject);
|
: this._world.createCdpHandle(remoteObject);
|
||||||
|
|
||||||
async function convertArgument(
|
async function convertArgument(
|
||||||
this: ExecutionContext,
|
this: ExecutionContext,
|
||||||
@ -377,16 +377,3 @@ const rewriteError = (error: Error): Protocol.Runtime.EvaluateResponse => {
|
|||||||
}
|
}
|
||||||
throw error;
|
throw error;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
export function createCdpHandle(
|
|
||||||
realm: IsolatedWorld,
|
|
||||||
remoteObject: Protocol.Runtime.RemoteObject
|
|
||||||
): JSHandle | ElementHandle<Node> {
|
|
||||||
if (remoteObject.subtype === 'node') {
|
|
||||||
return new CdpElementHandle(realm, remoteObject);
|
|
||||||
}
|
|
||||||
return new CdpJSHandle(realm, remoteObject);
|
|
||||||
}
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
import type {Protocol} from 'devtools-protocol';
|
import type {Protocol} from 'devtools-protocol';
|
||||||
|
|
||||||
import type {CDPSession} from '../api/CDPSession.js';
|
import type {CDPSession} from '../api/CDPSession.js';
|
||||||
|
import type {ElementHandle} from '../api/ElementHandle.js';
|
||||||
import type {JSHandle} from '../api/JSHandle.js';
|
import type {JSHandle} from '../api/JSHandle.js';
|
||||||
import {Realm} from '../api/Realm.js';
|
import {Realm} from '../api/Realm.js';
|
||||||
import type {TimeoutSettings} from '../common/TimeoutSettings.js';
|
import type {TimeoutSettings} from '../common/TimeoutSettings.js';
|
||||||
@ -17,9 +18,11 @@ import {disposeSymbol} from '../util/disposable.js';
|
|||||||
import {Mutex} from '../util/Mutex.js';
|
import {Mutex} from '../util/Mutex.js';
|
||||||
|
|
||||||
import type {Binding} from './Binding.js';
|
import type {Binding} from './Binding.js';
|
||||||
import {ExecutionContext, createCdpHandle} from './ExecutionContext.js';
|
import {CdpElementHandle} from './ElementHandle.js';
|
||||||
|
import {ExecutionContext} from './ExecutionContext.js';
|
||||||
import type {CdpFrame} from './Frame.js';
|
import type {CdpFrame} from './Frame.js';
|
||||||
import type {MAIN_WORLD, PUPPETEER_WORLD} from './IsolatedWorlds.js';
|
import type {MAIN_WORLD, PUPPETEER_WORLD} from './IsolatedWorlds.js';
|
||||||
|
import {CdpJSHandle} from './JSHandle.js';
|
||||||
import {addPageBinding} from './utils.js';
|
import {addPageBinding} from './utils.js';
|
||||||
import type {CdpWebWorker} from './WebWorker.js';
|
import type {CdpWebWorker} from './WebWorker.js';
|
||||||
|
|
||||||
@ -231,7 +234,7 @@ export class IsolatedWorld extends Realm {
|
|||||||
backendNodeId: backendNodeId,
|
backendNodeId: backendNodeId,
|
||||||
executionContextId: executionContext._contextId,
|
executionContextId: executionContext._contextId,
|
||||||
});
|
});
|
||||||
return createCdpHandle(this, object) as JSHandle<Node>;
|
return this.createCdpHandle(object) as JSHandle<Node>;
|
||||||
}
|
}
|
||||||
|
|
||||||
async adoptHandle<T extends JSHandle<Node>>(handle: T): Promise<T> {
|
async adoptHandle<T extends JSHandle<Node>>(handle: T): Promise<T> {
|
||||||
@ -266,6 +269,18 @@ export class IsolatedWorld extends Realm {
|
|||||||
return newHandle;
|
return newHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
createCdpHandle(
|
||||||
|
remoteObject: Protocol.Runtime.RemoteObject
|
||||||
|
): JSHandle | ElementHandle<Node> {
|
||||||
|
if (remoteObject.subtype === 'node') {
|
||||||
|
return new CdpElementHandle(this, remoteObject);
|
||||||
|
}
|
||||||
|
return new CdpJSHandle(this, remoteObject);
|
||||||
|
}
|
||||||
|
|
||||||
[disposeSymbol](): void {
|
[disposeSymbol](): void {
|
||||||
super[disposeSymbol]();
|
super[disposeSymbol]();
|
||||||
this.client.off('Runtime.bindingCalled', this.#onBindingCalled);
|
this.client.off('Runtime.bindingCalled', this.#onBindingCalled);
|
||||||
|
@ -64,7 +64,6 @@ import {Coverage} from './Coverage.js';
|
|||||||
import type {DeviceRequestPrompt} from './DeviceRequestPrompt.js';
|
import type {DeviceRequestPrompt} from './DeviceRequestPrompt.js';
|
||||||
import {CdpDialog} from './Dialog.js';
|
import {CdpDialog} from './Dialog.js';
|
||||||
import {EmulationManager} from './EmulationManager.js';
|
import {EmulationManager} from './EmulationManager.js';
|
||||||
import {createCdpHandle} from './ExecutionContext.js';
|
|
||||||
import {FirefoxTargetManager} from './FirefoxTargetManager.js';
|
import {FirefoxTargetManager} from './FirefoxTargetManager.js';
|
||||||
import type {CdpFrame} from './Frame.js';
|
import type {CdpFrame} from './Frame.js';
|
||||||
import {FrameManager} from './FrameManager.js';
|
import {FrameManager} from './FrameManager.js';
|
||||||
@ -576,10 +575,9 @@ export class CdpPage extends Page {
|
|||||||
prototypeObjectId: prototypeHandle.id,
|
prototypeObjectId: prototypeHandle.id,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return createCdpHandle(
|
return this.mainFrame()
|
||||||
this.mainFrame().mainRealm(),
|
.mainRealm()
|
||||||
response.objects
|
.createCdpHandle(response.objects) as HandleFor<Prototype[]>;
|
||||||
) as HandleFor<Prototype[]>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override async cookies(...urls: string[]): Promise<Cookie[]> {
|
override async cookies(...urls: string[]): Promise<Cookie[]> {
|
||||||
@ -814,7 +812,7 @@ export class CdpPage extends Page {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const values = event.args.map(arg => {
|
const values = event.args.map(arg => {
|
||||||
return createCdpHandle(context._world, arg);
|
return context._world.createCdpHandle(arg);
|
||||||
});
|
});
|
||||||
this.#addConsoleMessage(
|
this.#addConsoleMessage(
|
||||||
convertConsoleMessageLevel(event.type),
|
convertConsoleMessageLevel(event.type),
|
||||||
|
Loading…
Reference in New Issue
Block a user