From d070a73c46de6c771b55a3efc418e15c30a9a322 Mon Sep 17 00:00:00 2001 From: jrandolf <101637635+jrandolf@users.noreply.github.com> Date: Thu, 25 Aug 2022 17:01:30 +0200 Subject: [PATCH] chore: infer ElementHandle constructor params (#8843) --- src/common/ElementHandle.ts | 16 +++++++++------- src/common/util.ts | 14 ++++---------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/common/ElementHandle.ts b/src/common/ElementHandle.ts index 6737960733971..baef532ec4b1d 100644 --- a/src/common/ElementHandle.ts +++ b/src/common/ElementHandle.ts @@ -71,8 +71,6 @@ export class ElementHandle< ElementType extends Node = Element > extends JSHandle { #frame: Frame; - #page: Page; - #frameManager: FrameManager; /** * @internal @@ -80,14 +78,18 @@ export class ElementHandle< 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(); } /** diff --git a/src/common/util.ts b/src/common/util.ts index 025e3dab254df..0317938c6c560 100644 --- a/src/common/util.ts +++ b/src/common/util.ts @@ -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'; /** @@ -218,15 +219,8 @@ export function createJSHandle( remoteObject: Protocol.Runtime.RemoteObject ): JSHandle | ElementHandle { 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); }