diff --git a/docs/api/puppeteer.jshandle.evaluate.md b/docs/api/puppeteer.jshandle.evaluate.md index 78b4b1df122..a888acd18cb 100644 --- a/docs/api/puppeteer.jshandle.evaluate.md +++ b/docs/api/puppeteer.jshandle.evaluate.md @@ -10,7 +10,7 @@ Evaluates the given function with the current handle as its first argument. ```typescript class JSHandle { - abstract evaluate< + evaluate< Params extends unknown[], Func extends EvaluateFuncWith = EvaluateFuncWith, >( diff --git a/docs/api/puppeteer.jshandle.evaluatehandle.md b/docs/api/puppeteer.jshandle.evaluatehandle.md index 339f1cc452d..4c5c35f5ffb 100644 --- a/docs/api/puppeteer.jshandle.evaluatehandle.md +++ b/docs/api/puppeteer.jshandle.evaluatehandle.md @@ -10,7 +10,7 @@ Evaluates the given function with the current handle as its first argument. ```typescript class JSHandle { - abstract evaluateHandle< + evaluateHandle< Params extends unknown[], Func extends EvaluateFuncWith = EvaluateFuncWith, >( diff --git a/docs/api/puppeteer.jshandle.getproperties.md b/docs/api/puppeteer.jshandle.getproperties.md index c0bf247a804..f6ddb06ca48 100644 --- a/docs/api/puppeteer.jshandle.getproperties.md +++ b/docs/api/puppeteer.jshandle.getproperties.md @@ -10,13 +10,13 @@ Gets a map of handles representing the properties of the current handle. ```typescript class JSHandle { - abstract getProperties(): Promise>>; + getProperties(): Promise>; } ``` **Returns:** -Promise<Map<string, [JSHandle](./puppeteer.jshandle.md)<unknown>>> +Promise<Map<string, [JSHandle](./puppeteer.jshandle.md)>> ## Example diff --git a/docs/api/puppeteer.jshandle.getproperty.md b/docs/api/puppeteer.jshandle.getproperty.md index a2516f27b6c..8493699f170 100644 --- a/docs/api/puppeteer.jshandle.getproperty.md +++ b/docs/api/puppeteer.jshandle.getproperty.md @@ -10,7 +10,7 @@ Fetches a single property from the referenced object. ```typescript class JSHandle { - abstract getProperty( + getProperty( propertyName: HandleOr ): Promise>; } diff --git a/docs/api/puppeteer.jshandle.getproperty_1.md b/docs/api/puppeteer.jshandle.getproperty_1.md index 7c2c9f00c83..a61431d4a6a 100644 --- a/docs/api/puppeteer.jshandle.getproperty_1.md +++ b/docs/api/puppeteer.jshandle.getproperty_1.md @@ -8,7 +8,7 @@ sidebar_label: JSHandle.getProperty_1 ```typescript class JSHandle { - abstract getProperty(propertyName: string): Promise>; + getProperty(propertyName: string): Promise>; } ``` diff --git a/packages/puppeteer-core/src/api/ElementHandle.ts b/packages/puppeteer-core/src/api/ElementHandle.ts index b8aa7cab236..3ffdf0c1fe7 100644 --- a/packages/puppeteer-core/src/api/ElementHandle.ts +++ b/packages/puppeteer-core/src/api/ElementHandle.ts @@ -142,7 +142,7 @@ export abstract class ElementHandle< /** * @internal */ - protected handle; + protected readonly handle; /** * @internal @@ -208,7 +208,7 @@ export abstract class ElementHandle< /** * @internal */ - override evaluateHandle< + override async evaluateHandle< Params extends unknown[], Func extends EvaluateFuncWith = EvaluateFuncWith< ElementType, @@ -218,7 +218,7 @@ export abstract class ElementHandle< pageFunction: Func | string, ...args: Params ): Promise>>> { - return this.handle.evaluateHandle(pageFunction, ...args); + return await this.handle.evaluateHandle(pageFunction, ...args); } /** @@ -1269,11 +1269,6 @@ export abstract class ElementHandle< }); } - /** - * @internal - */ - abstract assertElementHasWorld(): asserts this; - /** * If the element is a form input, you can use {@link ElementHandle.autofill} * to test if the form is compatible with the browser's autofill diff --git a/packages/puppeteer-core/src/api/Environment.ts b/packages/puppeteer-core/src/api/Environment.ts new file mode 100644 index 00000000000..29e3cdab672 --- /dev/null +++ b/packages/puppeteer-core/src/api/Environment.ts @@ -0,0 +1,27 @@ +/** + * Copyright 2023 Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import {CDPSession} from '../common/Connection.js'; + +import {Realm} from './Realm.js'; + +/** + * @internal + */ +export interface Environment { + get client(): CDPSession; + mainRealm(): Realm; +} diff --git a/packages/puppeteer-core/src/api/Frame.ts b/packages/puppeteer-core/src/api/Frame.ts index 3134c3edb2b..34b6dce5241 100644 --- a/packages/puppeteer-core/src/api/Frame.ts +++ b/packages/puppeteer-core/src/api/Frame.ts @@ -20,7 +20,6 @@ import {Page, WaitTimeoutOptions} from '../api/Page.js'; import {CDPSession} from '../common/Connection.js'; import {DeviceRequestPrompt} from '../common/DeviceRequestPrompt.js'; import {EventEmitter} from '../common/EventEmitter.js'; -import {ExecutionContext} from '../common/ExecutionContext.js'; import {getQueryHandlerAndSelector} from '../common/GetQueryHandler.js'; import {transposeIterableHandle} from '../common/HandleIterator.js'; import { @@ -309,14 +308,7 @@ export abstract class Frame extends EventEmitter { /** * @internal */ - abstract _client(): CDPSession; - - /** - * @internal - */ - executionContext(): Promise { - throw new Error('Not implemented'); - } + abstract get client(): CDPSession; /** * @internal @@ -475,7 +467,7 @@ export abstract class Frame extends EventEmitter { * @returns A promise to the result of the function. */ @throwIfDetached - $eval< + async $eval< Selector extends string, Params extends unknown[], Func extends EvaluateFuncWith, Params> = EvaluateFuncWith< @@ -488,7 +480,7 @@ export abstract class Frame extends EventEmitter { ...args: Params ): Promise>> { pageFunction = withSourcePuppeteerURLIfNone(this.$eval.name, pageFunction); - return this.mainRealm().$eval(selector, pageFunction, ...args); + return await this.mainRealm().$eval(selector, pageFunction, ...args); } /** @@ -512,7 +504,7 @@ export abstract class Frame extends EventEmitter { * @returns A promise to the result of the function. */ @throwIfDetached - $$eval< + async $$eval< Selector extends string, Params extends unknown[], Func extends EvaluateFuncWith< @@ -525,7 +517,7 @@ export abstract class Frame extends EventEmitter { ...args: Params ): Promise>> { pageFunction = withSourcePuppeteerURLIfNone(this.$$eval.name, pageFunction); - return this.mainRealm().$$eval(selector, pageFunction, ...args); + return await this.mainRealm().$$eval(selector, pageFunction, ...args); } /** @@ -539,8 +531,8 @@ export abstract class Frame extends EventEmitter { * @param expression - the XPath expression to evaluate. */ @throwIfDetached - $x(expression: string): Promise>> { - return this.mainRealm().$x(expression); + async $x(expression: string): Promise>> { + return await this.mainRealm().$x(expression); } /** @@ -659,7 +651,7 @@ export abstract class Frame extends EventEmitter { * @returns the promise which resolve when the `pageFunction` returns a truthy value. */ @throwIfDetached - waitForFunction< + async waitForFunction< Params extends unknown[], Func extends EvaluateFunc = EvaluateFunc, >( @@ -667,18 +659,18 @@ export abstract class Frame extends EventEmitter { options: FrameWaitForFunctionOptions = {}, ...args: Params ): Promise>>> { - return this.mainRealm().waitForFunction( + return await (this.mainRealm().waitForFunction( pageFunction, options, ...args - ) as Promise>>>; + ) as Promise>>>); } /** * The full HTML contents of the frame, including the DOCTYPE. */ @throwIfDetached - content(): Promise { - return this.isolatedRealm().content(); + async content(): Promise { + return await this.isolatedRealm().content(); } /** @@ -922,8 +914,11 @@ export abstract class Frame extends EventEmitter { * @param selector - The selector to query for. */ @throwIfDetached - click(selector: string, options: Readonly = {}): Promise { - return this.isolatedRealm().click(selector, options); + async click( + selector: string, + options: Readonly = {} + ): Promise { + return await this.isolatedRealm().click(selector, options); } /** @@ -933,8 +928,8 @@ export abstract class Frame extends EventEmitter { * @throws Throws if there's no element matching `selector`. */ @throwIfDetached - focus(selector: string): Promise { - return this.isolatedRealm().focus(selector); + async focus(selector: string): Promise { + return await this.isolatedRealm().focus(selector); } /** @@ -945,8 +940,8 @@ export abstract class Frame extends EventEmitter { * @throws Throws if there's no element matching `selector`. */ @throwIfDetached - hover(selector: string): Promise { - return this.isolatedRealm().hover(selector); + async hover(selector: string): Promise { + return await this.isolatedRealm().hover(selector); } /** @@ -968,8 +963,8 @@ export abstract class Frame extends EventEmitter { * @throws Throws if there's no `