Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: infer client from context in JSHandle #8842

Merged
merged 1 commit into from Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/common/ElementHandle.ts
@@ -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,
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 3 additions & 6 deletions src/common/JSHandle.ts
Expand Up @@ -78,7 +78,6 @@ export class JSHandle<T = unknown> {
*/
[__JSHandleSymbol]?: T;

#client: CDPSession;
#disposed = false;
#context: ExecutionContext;
#remoteObject: Protocol.Runtime.RemoteObject;
Expand All @@ -87,7 +86,7 @@ export class JSHandle<T = unknown> {
* @internal
*/
get client(): CDPSession {
return this.#client;
return this.#context._client;
}

/**
Expand All @@ -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;
}

Expand Down Expand Up @@ -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,
});
Expand Down Expand Up @@ -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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/common/WebWorker.ts
Expand Up @@ -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
);
Expand Down
3 changes: 1 addition & 2 deletions src/common/util.ts
Expand Up @@ -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);
}

/**
Expand Down