mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: infer client from context in JSHandle (#8842)
This commit is contained in:
parent
5fba0dc932
commit
744a6e028a
@ -1,9 +1,8 @@
|
||||
import {Protocol} from 'devtools-protocol';
|
||||
import {assert} from '../util/assert.js';
|
||||
import {CDPSession} from './Connection.js';
|
||||
import {ExecutionContext} from './ExecutionContext.js';
|
||||
import {FrameManager} from './FrameManager.js';
|
||||
import {Frame} from './Frame.js';
|
||||
import {FrameManager} from './FrameManager.js';
|
||||
import {
|
||||
MAIN_WORLD,
|
||||
PUPPETEER_WORLD,
|
||||
@ -80,13 +79,12 @@ export class ElementHandle<
|
||||
*/
|
||||
constructor(
|
||||
context: ExecutionContext,
|
||||
client: CDPSession,
|
||||
remoteObject: Protocol.Runtime.RemoteObject,
|
||||
frame: Frame,
|
||||
page: Page,
|
||||
frameManager: FrameManager
|
||||
) {
|
||||
super(context, client, remoteObject);
|
||||
super(context, remoteObject);
|
||||
this.#frame = frame;
|
||||
this.#page = page;
|
||||
this.#frameManager = frameManager;
|
||||
|
@ -78,7 +78,6 @@ export class JSHandle<T = unknown> {
|
||||
*/
|
||||
[__JSHandleSymbol]?: T;
|
||||
|
||||
#client: CDPSession;
|
||||
#disposed = false;
|
||||
#context: ExecutionContext;
|
||||
#remoteObject: Protocol.Runtime.RemoteObject;
|
||||
@ -87,7 +86,7 @@ export class JSHandle<T = unknown> {
|
||||
* @internal
|
||||
*/
|
||||
get client(): CDPSession {
|
||||
return this.#client;
|
||||
return this.#context._client;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -102,11 +101,9 @@ export class JSHandle<T = unknown> {
|
||||
*/
|
||||
constructor(
|
||||
context: ExecutionContext,
|
||||
client: CDPSession,
|
||||
remoteObject: Protocol.Runtime.RemoteObject
|
||||
) {
|
||||
this.#context = context;
|
||||
this.#client = client;
|
||||
this.#remoteObject = remoteObject;
|
||||
}
|
||||
|
||||
@ -196,7 +193,7 @@ export class JSHandle<T = unknown> {
|
||||
assert(this.#remoteObject.objectId);
|
||||
// We use Runtime.getProperties rather than iterative building because the
|
||||
// iterative approach might create a distorted snapshot.
|
||||
const response = await this.#client.send('Runtime.getProperties', {
|
||||
const response = await this.client.send('Runtime.getProperties', {
|
||||
objectId: this.#remoteObject.objectId,
|
||||
ownProperties: true,
|
||||
});
|
||||
@ -247,7 +244,7 @@ export class JSHandle<T = unknown> {
|
||||
return;
|
||||
}
|
||||
this.#disposed = true;
|
||||
await releaseObject(this.#client, this.#remoteObject);
|
||||
await releaseObject(this.client, this.#remoteObject);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -93,7 +93,7 @@ export class WebWorker extends EventEmitter {
|
||||
return consoleAPICalled(
|
||||
event.type,
|
||||
event.args.map((object: Protocol.Runtime.RemoteObject) => {
|
||||
return new JSHandle(context, this.#client, object);
|
||||
return new JSHandle(context, object);
|
||||
}),
|
||||
event.stackTrace
|
||||
);
|
||||
|
@ -222,14 +222,13 @@ export function createJSHandle(
|
||||
const frameManager = frame._frameManager;
|
||||
return new ElementHandle(
|
||||
context,
|
||||
context._client,
|
||||
remoteObject,
|
||||
frame,
|
||||
frameManager.page(),
|
||||
frameManager
|
||||
);
|
||||
}
|
||||
return new JSHandle(context, context._client, remoteObject);
|
||||
return new JSHandle(context, remoteObject);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user