mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: infer ElementHandle constructor params (#8843)
This commit is contained in:
parent
744a6e028a
commit
d070a73c46
@ -71,8 +71,6 @@ export class ElementHandle<
|
|||||||
ElementType extends Node = Element
|
ElementType extends Node = Element
|
||||||
> extends JSHandle<ElementType> {
|
> extends JSHandle<ElementType> {
|
||||||
#frame: Frame;
|
#frame: Frame;
|
||||||
#page: Page;
|
|
||||||
#frameManager: FrameManager;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
@ -80,14 +78,18 @@ export class ElementHandle<
|
|||||||
constructor(
|
constructor(
|
||||||
context: ExecutionContext,
|
context: ExecutionContext,
|
||||||
remoteObject: Protocol.Runtime.RemoteObject,
|
remoteObject: Protocol.Runtime.RemoteObject,
|
||||||
frame: Frame,
|
frame: Frame
|
||||||
page: Page,
|
|
||||||
frameManager: FrameManager
|
|
||||||
) {
|
) {
|
||||||
super(context, remoteObject);
|
super(context, remoteObject);
|
||||||
this.#frame = frame;
|
this.#frame = frame;
|
||||||
this.#page = page;
|
}
|
||||||
this.#frameManager = frameManager;
|
|
||||||
|
get #frameManager(): FrameManager {
|
||||||
|
return this.#frame._frameManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
get #page(): Page {
|
||||||
|
return this.#frame.page();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,13 +18,14 @@ import {Protocol} from 'devtools-protocol';
|
|||||||
import type {Readable} from 'stream';
|
import type {Readable} from 'stream';
|
||||||
import {isNode} from '../environment.js';
|
import {isNode} from '../environment.js';
|
||||||
import {assert} from '../util/assert.js';
|
import {assert} from '../util/assert.js';
|
||||||
|
import {isErrorLike} from '../util/ErrorLike.js';
|
||||||
import {CDPSession} from './Connection.js';
|
import {CDPSession} from './Connection.js';
|
||||||
import {debug} from './Debug.js';
|
import {debug} from './Debug.js';
|
||||||
import {ElementHandle} from './ElementHandle.js';
|
import {ElementHandle} from './ElementHandle.js';
|
||||||
import {isErrorLike} from '../util/ErrorLike.js';
|
|
||||||
import {TimeoutError} from './Errors.js';
|
import {TimeoutError} from './Errors.js';
|
||||||
import {CommonEventEmitter} from './EventEmitter.js';
|
import {CommonEventEmitter} from './EventEmitter.js';
|
||||||
import {ExecutionContext} from './ExecutionContext.js';
|
import {ExecutionContext} from './ExecutionContext.js';
|
||||||
|
import {Frame} from './Frame.js';
|
||||||
import {JSHandle} from './JSHandle.js';
|
import {JSHandle} from './JSHandle.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -218,15 +219,8 @@ export function createJSHandle(
|
|||||||
remoteObject: Protocol.Runtime.RemoteObject
|
remoteObject: Protocol.Runtime.RemoteObject
|
||||||
): JSHandle | ElementHandle<Node> {
|
): JSHandle | ElementHandle<Node> {
|
||||||
const frame = context.frame();
|
const frame = context.frame();
|
||||||
if (remoteObject.subtype === 'node' && frame) {
|
if (remoteObject.subtype === 'node' && frame instanceof Frame) {
|
||||||
const frameManager = frame._frameManager;
|
return new ElementHandle(context, remoteObject, frame);
|
||||||
return new ElementHandle(
|
|
||||||
context,
|
|
||||||
remoteObject,
|
|
||||||
frame,
|
|
||||||
frameManager.page(),
|
|
||||||
frameManager
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return new JSHandle(context, remoteObject);
|
return new JSHandle(context, remoteObject);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user