chore: use abstract for implemented methods (#10774)

This commit is contained in:
jrandolf 2023-08-23 18:00:34 +02:00 committed by GitHub
parent 27636afacf
commit 5f8d2a43b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
33 changed files with 106 additions and 182 deletions

View File

@ -10,7 +10,7 @@ If the element is a form input, you can use [ElementHandle.autofill()](./puppete
```typescript ```typescript
class ElementHandle { class ElementHandle {
autofill(data: AutofillData): Promise<void>; abstract autofill(data: AutofillData): Promise<void>;
} }
``` ```

View File

@ -10,7 +10,10 @@ This method scrolls element into view if needed, and then uses [Page.mouse](./pu
```typescript ```typescript
class ElementHandle { class ElementHandle {
click(this: ElementHandle<Element>, options?: ClickOptions): Promise<void>; abstract click(
this: ElementHandle<Element>,
options?: ClickOptions
): Promise<void>;
} }
``` ```

View File

@ -4,13 +4,13 @@ sidebar_label: ElementHandle.contentFrame
# ElementHandle.contentFrame() method # ElementHandle.contentFrame() method
Resolves the frame associated with the element. Resolves the frame associated with the element, if any. Always exists for HTMLIFrameElements.
#### Signature: #### Signature:
```typescript ```typescript
class ElementHandle { class ElementHandle {
contentFrame(this: ElementHandle<HTMLIFrameElement>): Promise<Frame>; abstract contentFrame(this: ElementHandle<HTMLIFrameElement>): Promise<Frame>;
} }
``` ```

View File

@ -8,7 +8,7 @@ sidebar_label: ElementHandle.contentFrame_1
```typescript ```typescript
class ElementHandle { class ElementHandle {
contentFrame(): Promise<Frame | null>; abstract contentFrame(): Promise<Frame | null>;
} }
``` ```

View File

@ -10,7 +10,7 @@ This method scrolls element into view if needed, and then uses [Page](./puppetee
```typescript ```typescript
class ElementHandle { class ElementHandle {
hover(this: ElementHandle<Element>): Promise<void>; abstract hover(this: ElementHandle<Element>): Promise<void>;
} }
``` ```

View File

@ -9,7 +9,7 @@ ElementHandle represents an in-page DOM element.
#### Signature: #### Signature:
```typescript ```typescript
export declare class ElementHandle<ElementType extends Node = Element> extends JSHandle<ElementType> export declare abstract class ElementHandle<ElementType extends Node = Element> extends JSHandle<ElementType>
``` ```
**Extends:** [JSHandle](./puppeteer.jshandle.md)&lt;ElementType&gt; **Extends:** [JSHandle](./puppeteer.jshandle.md)&lt;ElementType&gt;
@ -42,8 +42,8 @@ The constructor for this class is marked as internal. Third-party code should no
## Properties ## Properties
| Property | Modifiers | Type | Description | | Property | Modifiers | Type | Description |
| -------- | --------------------- | ----------------------------- | ----------- | | -------- | --------------------- | ----------------------------- | ------------------------------------------ |
| frame | <code>readonly</code> | [Frame](./puppeteer.frame.md) | | | frame | <code>readonly</code> | [Frame](./puppeteer.frame.md) | Frame corresponding to the current handle. |
## Methods ## Methods
@ -60,7 +60,7 @@ The constructor for this class is marked as internal. Third-party code should no
| [boxModel()](./puppeteer.elementhandle.boxmodel.md) | | This method returns boxes of the element, or <code>null</code> if the element is not visible. | | [boxModel()](./puppeteer.elementhandle.boxmodel.md) | | This method returns boxes of the element, or <code>null</code> if the element is not visible. |
| [click(this, options)](./puppeteer.elementhandle.click.md) | | This method scrolls element into view if needed, and then uses [Page.mouse](./puppeteer.page.md) to click in the center of the element. If the element is detached from DOM, the method throws an error. | | [click(this, options)](./puppeteer.elementhandle.click.md) | | This method scrolls element into view if needed, and then uses [Page.mouse](./puppeteer.page.md) to click in the center of the element. If the element is detached from DOM, the method throws an error. |
| [clickablePoint(offset)](./puppeteer.elementhandle.clickablepoint.md) | | Returns the middle point within an element unless a specific offset is provided. | | [clickablePoint(offset)](./puppeteer.elementhandle.clickablepoint.md) | | Returns the middle point within an element unless a specific offset is provided. |
| [contentFrame(this)](./puppeteer.elementhandle.contentframe.md) | | Resolves the frame associated with the element. | | [contentFrame(this)](./puppeteer.elementhandle.contentframe.md) | | Resolves the frame associated with the element, if any. Always exists for HTMLIFrameElements. |
| [contentFrame()](./puppeteer.elementhandle.contentframe_1.md) | | | | [contentFrame()](./puppeteer.elementhandle.contentframe_1.md) | | |
| [drag(this, target)](./puppeteer.elementhandle.drag.md) | | This method creates and captures a dragevent from the element. | | [drag(this, target)](./puppeteer.elementhandle.drag.md) | | This method creates and captures a dragevent from the element. |
| [dragAndDrop(this, target, options)](./puppeteer.elementhandle.draganddrop.md) | | This method triggers a dragenter, dragover, and drop on the element. | | [dragAndDrop(this, target, options)](./puppeteer.elementhandle.draganddrop.md) | | This method triggers a dragenter, dragover, and drop on the element. |

View File

@ -10,7 +10,10 @@ Focuses the element, and then uses [Keyboard.down()](./puppeteer.keyboard.down.m
```typescript ```typescript
class ElementHandle { class ElementHandle {
press(key: KeyInput, options?: Readonly<KeyPressOptions>): Promise<void>; abstract press(
key: KeyInput,
options?: Readonly<KeyPressOptions>
): Promise<void>;
} }
``` ```

View File

@ -10,7 +10,7 @@ This method scrolls element into view if needed, and then uses [Touchscreen.tap(
```typescript ```typescript
class ElementHandle { class ElementHandle {
tap(this: ElementHandle<Element>): Promise<void>; abstract tap(this: ElementHandle<Element>): Promise<void>;
} }
``` ```

View File

@ -8,7 +8,7 @@ sidebar_label: ElementHandle.touchEnd
```typescript ```typescript
class ElementHandle { class ElementHandle {
touchEnd(this: ElementHandle<Element>): Promise<void>; abstract touchEnd(this: ElementHandle<Element>): Promise<void>;
} }
``` ```

View File

@ -8,7 +8,7 @@ sidebar_label: ElementHandle.touchMove
```typescript ```typescript
class ElementHandle { class ElementHandle {
touchMove(this: ElementHandle<Element>): Promise<void>; abstract touchMove(this: ElementHandle<Element>): Promise<void>;
} }
``` ```

View File

@ -8,7 +8,7 @@ sidebar_label: ElementHandle.touchStart
```typescript ```typescript
class ElementHandle { class ElementHandle {
touchStart(this: ElementHandle<Element>): Promise<void>; abstract touchStart(this: ElementHandle<Element>): Promise<void>;
} }
``` ```

View File

@ -12,7 +12,10 @@ To press a special key, like `Control` or `ArrowDown`, use [ElementHandle.press(
```typescript ```typescript
class ElementHandle { class ElementHandle {
type(text: string, options?: Readonly<KeyboardTypeOptions>): Promise<void>; abstract type(
text: string,
options?: Readonly<KeyboardTypeOptions>
): Promise<void>;
} }
``` ```

View File

@ -10,7 +10,7 @@ Either `null` or the handle itself if the handle is an instance of [ElementHandl
```typescript ```typescript
class JSHandle { class JSHandle {
asElement(): ElementHandle<Node> | null; abstract asElement(): ElementHandle<Node> | null;
} }
``` ```

View File

@ -10,7 +10,7 @@ Releases the object referenced by the handle for garbage collection.
```typescript ```typescript
class JSHandle { class JSHandle {
dispose(): Promise<void>; abstract dispose(): Promise<void>;
} }
``` ```

View File

@ -10,7 +10,7 @@ Evaluates the given function with the current handle as its first argument.
```typescript ```typescript
class JSHandle { class JSHandle {
evaluate< abstract evaluate<
Params extends unknown[], Params extends unknown[],
Func extends EvaluateFuncWith<T, Params> = EvaluateFuncWith<T, Params>, Func extends EvaluateFuncWith<T, Params> = EvaluateFuncWith<T, Params>,
>( >(

View File

@ -10,7 +10,7 @@ Evaluates the given function with the current handle as its first argument.
```typescript ```typescript
class JSHandle { class JSHandle {
evaluateHandle< abstract evaluateHandle<
Params extends unknown[], Params extends unknown[],
Func extends EvaluateFuncWith<T, Params> = EvaluateFuncWith<T, Params>, Func extends EvaluateFuncWith<T, Params> = EvaluateFuncWith<T, Params>,
>( >(

View File

@ -10,13 +10,13 @@ Gets a map of handles representing the properties of the current handle.
```typescript ```typescript
class JSHandle { class JSHandle {
getProperties(): Promise<Map<string, JSHandle>>; abstract getProperties(): Promise<Map<string, JSHandle<unknown>>>;
} }
``` ```
**Returns:** **Returns:**
Promise&lt;Map&lt;string, [JSHandle](./puppeteer.jshandle.md)&gt;&gt; Promise&lt;Map&lt;string, [JSHandle](./puppeteer.jshandle.md)&lt;unknown&gt;&gt;&gt;
## Example ## Example

View File

@ -10,7 +10,7 @@ Fetches a single property from the referenced object.
```typescript ```typescript
class JSHandle { class JSHandle {
getProperty<K extends keyof T>( abstract getProperty<K extends keyof T>(
propertyName: HandleOr<K> propertyName: HandleOr<K>
): Promise<HandleFor<T[K]>>; ): Promise<HandleFor<T[K]>>;
} }

View File

@ -8,7 +8,7 @@ sidebar_label: JSHandle.getProperty_1
```typescript ```typescript
class JSHandle { class JSHandle {
getProperty(propertyName: string): Promise<JSHandle<unknown>>; abstract getProperty(propertyName: string): Promise<JSHandle<unknown>>;
} }
``` ```

View File

@ -1,25 +0,0 @@
---
sidebar_label: JSHandle.getProperty_2
---
# JSHandle.getProperty() method
#### Signature:
```typescript
class JSHandle {
getProperty<K extends keyof T>(
propertyName: HandleOr<K>
): Promise<HandleFor<T[K]>>;
}
```
## Parameters
| Parameter | Type | Description |
| ------------ | -------------------------------------------- | ----------- |
| propertyName | [HandleOr](./puppeteer.handleor.md)&lt;K&gt; | |
**Returns:**
Promise&lt;[HandleFor](./puppeteer.handlefor.md)&lt;T\[K\]&gt;&gt;

View File

@ -10,7 +10,7 @@ A vanilla object representing the serializable portions of the referenced object
```typescript ```typescript
class JSHandle { class JSHandle {
jsonValue(): Promise<T>; abstract jsonValue(): Promise<T>;
} }
``` ```

View File

@ -13,7 +13,7 @@ Handles can be used as arguments for any evaluation function such as [Page.$eval
#### Signature: #### Signature:
```typescript ```typescript
export declare class JSHandle<T = unknown> export declare abstract class JSHandle<T = unknown>
``` ```
## Remarks ## Remarks
@ -43,7 +43,6 @@ const windowHandle = await page.evaluateHandle(() => window);
| [getProperties()](./puppeteer.jshandle.getproperties.md) | | Gets a map of handles representing the properties of the current handle. | | [getProperties()](./puppeteer.jshandle.getproperties.md) | | Gets a map of handles representing the properties of the current handle. |
| [getProperty(propertyName)](./puppeteer.jshandle.getproperty.md) | | Fetches a single property from the referenced object. | | [getProperty(propertyName)](./puppeteer.jshandle.getproperty.md) | | Fetches a single property from the referenced object. |
| [getProperty(propertyName)](./puppeteer.jshandle.getproperty_1.md) | | | | [getProperty(propertyName)](./puppeteer.jshandle.getproperty_1.md) | | |
| [getProperty(propertyName)](./puppeteer.jshandle.getproperty_2.md) | | |
| [jsonValue()](./puppeteer.jshandle.jsonvalue.md) | | A vanilla object representing the serializable portions of the referenced object. | | [jsonValue()](./puppeteer.jshandle.jsonvalue.md) | | A vanilla object representing the serializable portions of the referenced object. |
| [remoteObject()](./puppeteer.jshandle.remoteobject.md) | | Provides access to the [Protocol.Runtime.RemoteObject](https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-RemoteObject) backing this handle. | | [remoteObject()](./puppeteer.jshandle.remoteobject.md) | | Provides access to the [Protocol.Runtime.RemoteObject](https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-RemoteObject) backing this handle. |
| [toString()](./puppeteer.jshandle.tostring.md) | | Returns a string representation of the JSHandle. | | [toString()](./puppeteer.jshandle.tostring.md) | | Returns a string representation of the JSHandle. |

View File

@ -10,7 +10,7 @@ Provides access to the [Protocol.Runtime.RemoteObject](https://chromedevtools.gi
```typescript ```typescript
class JSHandle { class JSHandle {
remoteObject(): Protocol.Runtime.RemoteObject; abstract remoteObject(): Protocol.Runtime.RemoteObject;
} }
``` ```

View File

@ -10,7 +10,7 @@ Returns a string representation of the JSHandle.
```typescript ```typescript
class JSHandle { class JSHandle {
toString(): string; abstract toString(): string;
} }
``` ```

View File

@ -17,8 +17,6 @@
import {Protocol} from 'devtools-protocol'; import {Protocol} from 'devtools-protocol';
import {Frame} from '../api/Frame.js'; import {Frame} from '../api/Frame.js';
import {CDPSession} from '../common/Connection.js';
import {ExecutionContext} from '../common/ExecutionContext.js';
import {getQueryHandlerAndSelector} from '../common/GetQueryHandler.js'; import {getQueryHandlerAndSelector} from '../common/GetQueryHandler.js';
import {WaitForSelectorOptions} from '../common/IsolatedWorld.js'; import {WaitForSelectorOptions} from '../common/IsolatedWorld.js';
import {LazyArg} from '../common/LazyArg.js'; import {LazyArg} from '../common/LazyArg.js';
@ -39,9 +37,9 @@ import {assert} from '../util/assert.js';
import {AsyncIterableUtil} from '../util/AsyncIterableUtil.js'; import {AsyncIterableUtil} from '../util/AsyncIterableUtil.js';
import { import {
KeyboardTypeOptions,
KeyPressOptions, KeyPressOptions,
MouseClickOptions, MouseClickOptions,
KeyboardTypeOptions,
} from './Input.js'; } from './Input.js';
import {JSHandle} from './JSHandle.js'; import {JSHandle} from './JSHandle.js';
import {ScreenshotOptions} from './Page.js'; import {ScreenshotOptions} from './Page.js';
@ -143,7 +141,7 @@ export interface Point {
* @public * @public
*/ */
export class ElementHandle< export abstract class ElementHandle<
ElementType extends Node = Element, ElementType extends Node = Element,
> extends JSHandle<ElementType> { > extends JSHandle<ElementType> {
/** /**
@ -242,6 +240,13 @@ export class ElementHandle<
return this.handle.toString(); return this.handle.toString();
} }
/**
* @internal
*/
override remoteObject(): Protocol.Runtime.RemoteObject {
return this.handle.remoteObject();
}
/** /**
* @internal * @internal
*/ */
@ -254,22 +259,9 @@ export class ElementHandle<
} }
/** /**
* @internal * Frame corresponding to the current handle.
*/ */
override executionContext(): ExecutionContext { abstract get frame(): Frame;
throw new Error('Not implemented');
}
/**
* @internal
*/
override get client(): CDPSession {
throw new Error('Not implemented');
}
get frame(): Frame {
throw new Error('Not implemented');
}
/** /**
* Queries the current element for an element matching the given selector. * Queries the current element for an element matching the given selector.
@ -629,13 +621,11 @@ export class ElementHandle<
} }
/** /**
* Resolves the frame associated with the element. * Resolves the frame associated with the element, if any. Always exists for
* HTMLIFrameElements.
*/ */
async contentFrame(this: ElementHandle<HTMLIFrameElement>): Promise<Frame>; abstract contentFrame(this: ElementHandle<HTMLIFrameElement>): Promise<Frame>;
async contentFrame(): Promise<Frame | null>; abstract contentFrame(): Promise<Frame | null>;
async contentFrame(): Promise<Frame | null> {
throw new Error('Not implemented');
}
/** /**
* Returns the middle point within an element unless a specific offset is provided. * Returns the middle point within an element unless a specific offset is provided.
@ -650,22 +640,17 @@ export class ElementHandle<
* uses {@link Page} to hover over the center of the element. * uses {@link Page} to hover over the center of the element.
* If the element is detached from DOM, the method throws an error. * If the element is detached from DOM, the method throws an error.
*/ */
async hover(this: ElementHandle<Element>): Promise<void> { abstract hover(this: ElementHandle<Element>): Promise<void>;
throw new Error('Not implemented');
}
/** /**
* This method scrolls element into view if needed, and then * This method scrolls element into view if needed, and then
* uses {@link Page | Page.mouse} to click in the center of the element. * uses {@link Page | Page.mouse} to click in the center of the element.
* If the element is detached from DOM, the method throws an error. * If the element is detached from DOM, the method throws an error.
*/ */
async click( abstract click(
this: ElementHandle<Element>, this: ElementHandle<Element>,
options?: ClickOptions options?: ClickOptions
): Promise<void>; ): Promise<void>;
async click(this: ElementHandle<Element>): Promise<void> {
throw new Error('Not implemented');
}
/** /**
* This method creates and captures a dragevent from the element. * This method creates and captures a dragevent from the element.
@ -807,21 +792,13 @@ export class ElementHandle<
* {@link Touchscreen.tap} to tap in the center of the element. * {@link Touchscreen.tap} to tap in the center of the element.
* If the element is detached from DOM, the method throws an error. * If the element is detached from DOM, the method throws an error.
*/ */
async tap(this: ElementHandle<Element>): Promise<void> { abstract tap(this: ElementHandle<Element>): Promise<void>;
throw new Error('Not implemented');
}
async touchStart(this: ElementHandle<Element>): Promise<void> { abstract touchStart(this: ElementHandle<Element>): Promise<void>;
throw new Error('Not implemented');
}
async touchMove(this: ElementHandle<Element>): Promise<void> { abstract touchMove(this: ElementHandle<Element>): Promise<void>;
throw new Error('Not implemented');
}
async touchEnd(this: ElementHandle<Element>): Promise<void> { abstract touchEnd(this: ElementHandle<Element>): Promise<void>;
throw new Error('Not implemented');
}
/** /**
* Calls {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus | focus} on the element. * Calls {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus | focus} on the element.
@ -860,13 +837,10 @@ export class ElementHandle<
* *
* @param options - Delay in milliseconds. Defaults to 0. * @param options - Delay in milliseconds. Defaults to 0.
*/ */
async type( abstract type(
text: string, text: string,
options?: Readonly<KeyboardTypeOptions> options?: Readonly<KeyboardTypeOptions>
): Promise<void>; ): Promise<void>;
async type(): Promise<void> {
throw new Error('Not implemented');
}
/** /**
* Focuses the element, and then uses {@link Keyboard.down} and {@link Keyboard.up}. * Focuses the element, and then uses {@link Keyboard.down} and {@link Keyboard.up}.
@ -882,13 +856,10 @@ export class ElementHandle<
* @param key - Name of key to press, such as `ArrowLeft`. * @param key - Name of key to press, such as `ArrowLeft`.
* See {@link KeyInput} for a list of all key names. * See {@link KeyInput} for a list of all key names.
*/ */
async press( abstract press(
key: KeyInput, key: KeyInput,
options?: Readonly<KeyPressOptions> options?: Readonly<KeyPressOptions>
): Promise<void>; ): Promise<void>;
async press(): Promise<void> {
throw new Error('Not implemented');
}
/** /**
* This method returns the bounding box of the element (relative to the main frame), * This method returns the bounding box of the element (relative to the main frame),
@ -1205,9 +1176,7 @@ export class ElementHandle<
/** /**
* @internal * @internal
*/ */
assertElementHasWorld(): asserts this { abstract assertElementHasWorld(): asserts this;
assert(this.executionContext()._world);
}
/** /**
* If the element is a form input, you can use {@link ElementHandle.autofill} * If the element is a form input, you can use {@link ElementHandle.autofill}
@ -1234,10 +1203,7 @@ export class ElementHandle<
* }); * });
* ``` * ```
*/ */
autofill(data: AutofillData): Promise<void>; abstract autofill(data: AutofillData): Promise<void>;
autofill(): Promise<void> {
throw new Error('Not implemented');
}
} }
/** /**

View File

@ -16,8 +16,6 @@
import Protocol from 'devtools-protocol'; import Protocol from 'devtools-protocol';
import {CDPSession} from '../common/Connection.js';
import {ExecutionContext} from '../common/ExecutionContext.js';
import {EvaluateFuncWith, HandleFor, HandleOr} from '../common/types.js'; import {EvaluateFuncWith, HandleFor, HandleOr} from '../common/types.js';
import {ElementHandle} from './ElementHandle.js'; import {ElementHandle} from './ElementHandle.js';
@ -43,7 +41,7 @@ import {ElementHandle} from './ElementHandle.js';
* *
* @public * @public
*/ */
export class JSHandle<T = unknown> { export abstract class JSHandle<T = unknown> {
/** /**
* Used for nominally typing {@link JSHandle}. * Used for nominally typing {@link JSHandle}.
*/ */
@ -61,62 +59,36 @@ export class JSHandle<T = unknown> {
throw new Error('Not implemented'); throw new Error('Not implemented');
} }
/**
* @internal
*/
executionContext(): ExecutionContext {
throw new Error('Not implemented');
}
/**
* @internal
*/
get client(): CDPSession {
throw new Error('Not implemented');
}
/** /**
* Evaluates the given function with the current handle as its first argument. * Evaluates the given function with the current handle as its first argument.
*/ */
async evaluate< abstract evaluate<
Params extends unknown[], Params extends unknown[],
Func extends EvaluateFuncWith<T, Params> = EvaluateFuncWith<T, Params>, Func extends EvaluateFuncWith<T, Params> = EvaluateFuncWith<T, Params>,
>( >(
pageFunction: Func | string, pageFunction: Func | string,
...args: Params ...args: Params
): Promise<Awaited<ReturnType<Func>>>; ): Promise<Awaited<ReturnType<Func>>>;
async evaluate(): Promise<unknown> {
throw new Error('Not implemented');
}
/** /**
* Evaluates the given function with the current handle as its first argument. * Evaluates the given function with the current handle as its first argument.
* *
*/ */
async evaluateHandle< abstract evaluateHandle<
Params extends unknown[], Params extends unknown[],
Func extends EvaluateFuncWith<T, Params> = EvaluateFuncWith<T, Params>, Func extends EvaluateFuncWith<T, Params> = EvaluateFuncWith<T, Params>,
>( >(
pageFunction: Func | string, pageFunction: Func | string,
...args: Params ...args: Params
): Promise<HandleFor<Awaited<ReturnType<Func>>>>; ): Promise<HandleFor<Awaited<ReturnType<Func>>>>;
async evaluateHandle(): Promise<HandleFor<unknown>> {
throw new Error('Not implemented');
}
/** /**
* Fetches a single property from the referenced object. * Fetches a single property from the referenced object.
*/ */
async getProperty<K extends keyof T>( abstract getProperty<K extends keyof T>(
propertyName: HandleOr<K> propertyName: HandleOr<K>
): Promise<HandleFor<T[K]>>; ): Promise<HandleFor<T[K]>>;
async getProperty(propertyName: string): Promise<JSHandle<unknown>>; abstract getProperty(propertyName: string): Promise<JSHandle<unknown>>;
async getProperty<K extends keyof T>(
propertyName: HandleOr<K>
): Promise<HandleFor<T[K]>>;
async getProperty<K extends keyof T>(): Promise<HandleFor<T[K]>> {
throw new Error('Not implemented');
}
/** /**
* Gets a map of handles representing the properties of the current handle. * Gets a map of handles representing the properties of the current handle.
@ -136,9 +108,7 @@ export class JSHandle<T = unknown> {
* children; // holds elementHandles to all children of document.body * children; // holds elementHandles to all children of document.body
* ``` * ```
*/ */
async getProperties(): Promise<Map<string, JSHandle>> { abstract getProperties(): Promise<Map<string, JSHandle<unknown>>>;
throw new Error('Not implemented');
}
/** /**
* A vanilla object representing the serializable portions of the * A vanilla object representing the serializable portions of the
@ -148,24 +118,18 @@ export class JSHandle<T = unknown> {
* @remarks * @remarks
* If the object has a `toJSON` function, it **will not** be called. * If the object has a `toJSON` function, it **will not** be called.
*/ */
async jsonValue(): Promise<T> { abstract jsonValue(): Promise<T>;
throw new Error('Not implemented');
}
/** /**
* Either `null` or the handle itself if the handle is an * Either `null` or the handle itself if the handle is an
* instance of {@link ElementHandle}. * instance of {@link ElementHandle}.
*/ */
asElement(): ElementHandle<Node> | null { abstract asElement(): ElementHandle<Node> | null;
throw new Error('Not implemented');
}
/** /**
* Releases the object referenced by the handle for garbage collection. * Releases the object referenced by the handle for garbage collection.
*/ */
async dispose(): Promise<void> { abstract dispose(): Promise<void>;
throw new Error('Not implemented');
}
/** /**
* Returns a string representation of the JSHandle. * Returns a string representation of the JSHandle.
@ -173,23 +137,17 @@ export class JSHandle<T = unknown> {
* @remarks * @remarks
* Useful during debugging. * Useful during debugging.
*/ */
toString(): string { abstract toString(): string;
throw new Error('Not implemented');
}
/** /**
* @internal * @internal
*/ */
get id(): string | undefined { abstract get id(): string | undefined;
throw new Error('Not implemented');
}
/** /**
* Provides access to the * Provides access to the
* {@link https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-RemoteObject | Protocol.Runtime.RemoteObject} * {@link https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-RemoteObject | Protocol.Runtime.RemoteObject}
* backing this handle. * backing this handle.
*/ */
remoteObject(): Protocol.Runtime.RemoteObject { abstract remoteObject(): Protocol.Runtime.RemoteObject;
throw new Error('Not implemented');
}
} }

View File

@ -21,6 +21,7 @@ import {assert} from '../util/assert.js';
import {AsyncIterableUtil} from '../util/AsyncIterableUtil.js'; import {AsyncIterableUtil} from '../util/AsyncIterableUtil.js';
import {CDPSession} from './Connection.js'; import {CDPSession} from './Connection.js';
import {CDPJSHandle} from './JSHandle.js';
import {QueryHandler, QuerySelector} from './QueryHandler.js'; import {QueryHandler, QuerySelector} from './QueryHandler.js';
import {AwaitableIterable} from './types.js'; import {AwaitableIterable} from './types.js';
@ -105,7 +106,9 @@ export class ARIAQueryHandler extends QueryHandler {
element: ElementHandle<Node>, element: ElementHandle<Node>,
selector: string selector: string
): AwaitableIterable<ElementHandle<Node>> { ): AwaitableIterable<ElementHandle<Node>> {
const context = element.executionContext(); const context = (
element as unknown as CDPJSHandle<Node>
).executionContext();
const {name, role} = parseARIASelector(selector); const {name, role} = parseARIASelector(selector);
const results = await queryAXTree(context._client, element, name, role); const results = await queryAXTree(context._client, element, name, role);
const world = context._world!; const world = context._world!;

View File

@ -76,14 +76,14 @@ export class CDPElementHandle<
/** /**
* @internal * @internal
*/ */
override executionContext(): ExecutionContext { executionContext(): ExecutionContext {
return this.handle.executionContext(); return this.handle.executionContext();
} }
/** /**
* @internal * @internal
*/ */
override get client(): CDPSession { get client(): CDPSession {
return this.handle.client; return this.handle.client;
} }
@ -527,6 +527,10 @@ export class CDPElementHandle<
card: data.creditCard, card: data.creditCard,
}); });
} }
override assertElementHasWorld(): asserts this {
assert(this.executionContext()._world);
}
} }
function computeQuadArea(quad: Point[]): number { function computeQuadArea(quad: Point[]): number {

View File

@ -105,7 +105,9 @@ export class ExecutionContext {
selector: string selector: string
): Promise<JSHandle<Node[]>> => { ): Promise<JSHandle<Node[]>> => {
const results = ARIAQueryHandler.queryAll(element, selector); const results = ARIAQueryHandler.queryAll(element, selector);
return element.executionContext().evaluateHandle( return (element as unknown as CDPJSHandle<Node>)
.executionContext()
.evaluateHandle(
(...elements) => { (...elements) => {
return elements; return elements;
}, },

View File

@ -29,6 +29,7 @@ import {ExecutionContext} from './ExecutionContext.js';
import {Frame} from './Frame.js'; import {Frame} from './Frame.js';
import {FrameManager} from './FrameManager.js'; import {FrameManager} from './FrameManager.js';
import {MAIN_WORLD, PUPPETEER_WORLD} from './IsolatedWorlds.js'; import {MAIN_WORLD, PUPPETEER_WORLD} from './IsolatedWorlds.js';
import {CDPJSHandle} from './JSHandle.js';
import {LifecycleWatcher, PuppeteerLifeCycleEvent} from './LifecycleWatcher.js'; import {LifecycleWatcher, PuppeteerLifeCycleEvent} from './LifecycleWatcher.js';
import {TimeoutSettings} from './TimeoutSettings.js'; import {TimeoutSettings} from './TimeoutSettings.js';
import { import {
@ -500,7 +501,7 @@ export class IsolatedWorld implements Realm {
async adoptHandle<T extends JSHandle<Node>>(handle: T): Promise<T> { async adoptHandle<T extends JSHandle<Node>>(handle: T): Promise<T> {
const context = await this.executionContext(); const context = await this.executionContext();
assert( assert(
handle.executionContext() !== context, (handle as unknown as CDPJSHandle<Node>).executionContext() !== context,
'Cannot adopt handle that already belongs to this execution context' 'Cannot adopt handle that already belongs to this execution context'
); );
const nodeInfo = await this.#client.send('DOM.describeNode', { const nodeInfo = await this.#client.send('DOM.describeNode', {
@ -511,7 +512,9 @@ export class IsolatedWorld implements Realm {
async transferHandle<T extends JSHandle<Node>>(handle: T): Promise<T> { async transferHandle<T extends JSHandle<Node>>(handle: T): Promise<T> {
const context = await this.executionContext(); const context = await this.executionContext();
if (handle.executionContext() === context) { if (
(handle as unknown as CDPJSHandle<Node>).executionContext() === context
) {
return handle; return handle;
} }
const info = await this.#client.send('DOM.describeNode', { const info = await this.#client.send('DOM.describeNode', {

View File

@ -51,11 +51,11 @@ export class CDPJSHandle<T = unknown> extends JSHandle<T> {
this.#remoteObject = remoteObject; this.#remoteObject = remoteObject;
} }
override executionContext(): ExecutionContext { executionContext(): ExecutionContext {
return this.#context; return this.#context;
} }
override get client(): CDPSession { get client(): CDPSession {
return this.#context._client; return this.#context._client;
} }

View File

@ -67,7 +67,7 @@ export class ElementHandle<
/** /**
* @internal * @internal
*/ */
override assertElementHasWorld(): asserts this { assertElementHasWorld(): asserts this {
// TODO: Should assert element has a Sandbox // TODO: Should assert element has a Sandbox
return; return;
} }

View File

@ -15,6 +15,7 @@
*/ */
import * as Bidi from 'chromium-bidi/lib/cjs/protocol/protocol.js'; import * as Bidi from 'chromium-bidi/lib/cjs/protocol/protocol.js';
import Protocol from 'devtools-protocol';
import {ElementHandle} from '../../api/ElementHandle.js'; import {ElementHandle} from '../../api/ElementHandle.js';
import {JSHandle as BaseJSHandle} from '../../api/JSHandle.js'; import {JSHandle as BaseJSHandle} from '../../api/JSHandle.js';
@ -167,4 +168,8 @@ export class JSHandle<T = unknown> extends BaseJSHandle<T> {
remoteValue(): Bidi.Script.RemoteValue { remoteValue(): Bidi.Script.RemoteValue {
return this.#remoteValue; return this.#remoteValue;
} }
override remoteObject(): Protocol.Runtime.RemoteObject {
throw new Error('Not available in WebDriver BiDi');
}
} }