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 ElementHandle constructor params #8843

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
16 changes: 9 additions & 7 deletions src/common/ElementHandle.ts
Expand Up @@ -71,23 +71,25 @@ export class ElementHandle<
ElementType extends Node = Element
> extends JSHandle<ElementType> {
#frame: Frame;
#page: Page;
#frameManager: FrameManager;

/**
* @internal
*/
constructor(
context: ExecutionContext,
remoteObject: Protocol.Runtime.RemoteObject,
frame: Frame,
page: Page,
frameManager: FrameManager
frame: Frame
) {
super(context, remoteObject);
this.#frame = frame;
this.#page = page;
this.#frameManager = frameManager;
}

get #frameManager(): FrameManager {
return this.#frame._frameManager;
}

get #page(): Page {
return this.#frame.page();
}

/**
Expand Down
14 changes: 4 additions & 10 deletions src/common/util.ts
Expand Up @@ -18,13 +18,14 @@ import {Protocol} from 'devtools-protocol';
import type {Readable} from 'stream';
import {isNode} from '../environment.js';
import {assert} from '../util/assert.js';
import {isErrorLike} from '../util/ErrorLike.js';
import {CDPSession} from './Connection.js';
import {debug} from './Debug.js';
import {ElementHandle} from './ElementHandle.js';
import {isErrorLike} from '../util/ErrorLike.js';
import {TimeoutError} from './Errors.js';
import {CommonEventEmitter} from './EventEmitter.js';
import {ExecutionContext} from './ExecutionContext.js';
import {Frame} from './Frame.js';
import {JSHandle} from './JSHandle.js';

/**
Expand Down Expand Up @@ -218,15 +219,8 @@ export function createJSHandle(
remoteObject: Protocol.Runtime.RemoteObject
): JSHandle | ElementHandle<Node> {
const frame = context.frame();
if (remoteObject.subtype === 'node' && frame) {
const frameManager = frame._frameManager;
return new ElementHandle(
context,
remoteObject,
frame,
frameManager.page(),
frameManager
);
if (remoteObject.subtype === 'node' && frame instanceof Frame) {
return new ElementHandle(context, remoteObject, frame);
}
return new JSHandle(context, remoteObject);
}
Expand Down