docs: add DeviceRequestPrompt documentation (#9918)

This commit is contained in:
Nikolay Vitkov 2023-03-27 13:16:51 +02:00 committed by GitHub
parent 16bf0dc798
commit bb37df5f64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 230 additions and 47 deletions

View File

@ -7,7 +7,7 @@ sidebar_label: API
## Classes ## Classes
| Class | Description | | Class | Description |
| ------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | --------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Accessibility](./puppeteer.accessibility.md) | The Accessibility class provides methods for inspecting Chromium's accessibility tree. The accessibility tree is used by assistive technology such as [screen readers](https://en.wikipedia.org/wiki/Screen_reader) or [switches](https://en.wikipedia.org/wiki/Switch_access). | | [Accessibility](./puppeteer.accessibility.md) | The Accessibility class provides methods for inspecting Chromium's accessibility tree. The accessibility tree is used by assistive technology such as [screen readers](https://en.wikipedia.org/wiki/Screen_reader) or [switches](https://en.wikipedia.org/wiki/Switch_access). |
| [Browser](./puppeteer.browser.md) | A Browser is created when Puppeteer connects to a Chromium instance, either through [PuppeteerNode.launch()](./puppeteer.puppeteernode.launch.md) or [Puppeteer.connect()](./puppeteer.puppeteer.connect.md). | | [Browser](./puppeteer.browser.md) | A Browser is created when Puppeteer connects to a Chromium instance, either through [PuppeteerNode.launch()](./puppeteer.puppeteernode.launch.md) or [Puppeteer.connect()](./puppeteer.puppeteer.connect.md). |
| [BrowserContext](./puppeteer.browsercontext.md) | BrowserContexts provide a way to operate multiple independent browser sessions. When a browser is launched, it has a single BrowserContext used by default. The method [Browser.newPage](./puppeteer.browser.newpage.md) creates a page in the default browser context. | | [BrowserContext](./puppeteer.browsercontext.md) | BrowserContexts provide a way to operate multiple independent browser sessions. When a browser is launched, it has a single BrowserContext used by default. The method [Browser.newPage](./puppeteer.browser.newpage.md) creates a page in the default browser context. |
@ -18,6 +18,8 @@ sidebar_label: API
| [Coverage](./puppeteer.coverage.md) | The Coverage class provides methods to gathers information about parts of JavaScript and CSS that were used by the page. | | [Coverage](./puppeteer.coverage.md) | The Coverage class provides methods to gathers information about parts of JavaScript and CSS that were used by the page. |
| [CSSCoverage](./puppeteer.csscoverage.md) | | | [CSSCoverage](./puppeteer.csscoverage.md) | |
| [CustomError](./puppeteer.customerror.md) | | | [CustomError](./puppeteer.customerror.md) | |
| [DeviceRequestPrompt](./puppeteer.devicerequestprompt.md) | Device request prompts let you respond to the page requesting for a device through an API like WebBluetooth. |
| [DeviceRequestPromptDevice](./puppeteer.devicerequestpromptdevice.md) | Device in a request prompt. |
| [Dialog](./puppeteer.dialog.md) | Dialog instances are dispatched by the [Page](./puppeteer.page.md) via the <code>dialog</code> event. | | [Dialog](./puppeteer.dialog.md) | Dialog instances are dispatched by the [Page](./puppeteer.page.md) via the <code>dialog</code> event. |
| [ElementHandle](./puppeteer.elementhandle.md) | ElementHandle represents an in-page DOM element. | | [ElementHandle](./puppeteer.elementhandle.md) | ElementHandle represents an in-page DOM element. |
| [EventEmitter](./puppeteer.eventemitter.md) | The EventEmitter class that many Puppeteer classes extend. | | [EventEmitter](./puppeteer.eventemitter.md) | The EventEmitter class that many Puppeteer classes extend. |

View File

@ -0,0 +1,19 @@
---
sidebar_label: DeviceRequestPrompt.cancel
---
# DeviceRequestPrompt.cancel() method
Cancel the prompt.
#### Signature:
```typescript
class DeviceRequestPrompt {
cancel(): Promise<void>;
}
```
**Returns:**
Promise&lt;void&gt;

View File

@ -0,0 +1,15 @@
---
sidebar_label: DeviceRequestPrompt.devices
---
# DeviceRequestPrompt.devices property
Current list of selectable devices.
#### Signature:
```typescript
class DeviceRequestPrompt {
devices: DeviceRequestPromptDevice[];
}
```

View File

@ -0,0 +1,45 @@
---
sidebar_label: DeviceRequestPrompt
---
# DeviceRequestPrompt class
Device request prompts let you respond to the page requesting for a device through an API like WebBluetooth.
#### Signature:
```typescript
export declare class DeviceRequestPrompt
```
## Remarks
`DeviceRequestPrompt` instances are returned via the [Page.waitForDevicePrompt()](./puppeteer.page.waitfordeviceprompt.md) method.
The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `DeviceRequestPrompt` class.
## Example
```ts
const [deviceRequest] = Promise.all([
page.waitForDevicePrompt(),
page.click('#connect-bluetooth'),
]);
await devicePrompt.select(
await devicePrompt.waitForDevice(({name}) => name.includes('My Device'))
);
```
## Properties
| Property | Modifiers | Type | Description |
| ----------------------------------------------------- | --------- | ------------------------------------------------------------------------- | ----------------------------------- |
| [devices](./puppeteer.devicerequestprompt.devices.md) | | [DeviceRequestPromptDevice](./puppeteer.devicerequestpromptdevice.md)\[\] | Current list of selectable devices. |
## Methods
| Method | Modifiers | Description |
| ---------------------------------------------------------------------------------- | --------- | ------------------------------------------------------------ |
| [cancel()](./puppeteer.devicerequestprompt.cancel.md) | | Cancel the prompt. |
| [select(device)](./puppeteer.devicerequestprompt.select.md) | | Select a device in the prompt's list. |
| [waitForDevice(filter, options)](./puppeteer.devicerequestprompt.waitfordevice.md) | | Resolve to the first device in the prompt matching a filter. |

View File

@ -0,0 +1,25 @@
---
sidebar_label: DeviceRequestPrompt.select
---
# DeviceRequestPrompt.select() method
Select a device in the prompt's list.
#### Signature:
```typescript
class DeviceRequestPrompt {
select(device: DeviceRequestPromptDevice): Promise<void>;
}
```
## Parameters
| Parameter | Type | Description |
| --------- | --------------------------------------------------------------------- | ----------- |
| device | [DeviceRequestPromptDevice](./puppeteer.devicerequestpromptdevice.md) | |
**Returns:**
Promise&lt;void&gt;

View File

@ -0,0 +1,29 @@
---
sidebar_label: DeviceRequestPrompt.waitForDevice
---
# DeviceRequestPrompt.waitForDevice() method
Resolve to the first device in the prompt matching a filter.
#### Signature:
```typescript
class DeviceRequestPrompt {
waitForDevice(
filter: (device: DeviceRequestPromptDevice) => boolean,
options?: WaitTimeoutOptions
): Promise<DeviceRequestPromptDevice>;
}
```
## Parameters
| Parameter | Type | Description |
| --------- | --------------------------------------------------------------------------------------------- | ------------ |
| filter | (device: [DeviceRequestPromptDevice](./puppeteer.devicerequestpromptdevice.md)) =&gt; boolean | |
| options | [WaitTimeoutOptions](./puppeteer.waittimeoutoptions.md) | _(Optional)_ |
**Returns:**
Promise&lt;[DeviceRequestPromptDevice](./puppeteer.devicerequestpromptdevice.md)&gt;

View File

@ -0,0 +1,15 @@
---
sidebar_label: DeviceRequestPromptDevice.id
---
# DeviceRequestPromptDevice.id property
Device id during a prompt.
#### Signature:
```typescript
class DeviceRequestPromptDevice {
id: string;
}
```

View File

@ -0,0 +1,24 @@
---
sidebar_label: DeviceRequestPromptDevice
---
# DeviceRequestPromptDevice class
Device in a request prompt.
#### Signature:
```typescript
export declare class DeviceRequestPromptDevice
```
## Remarks
The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `DeviceRequestPromptDevice` class.
## Properties
| Property | Modifiers | Type | Description |
| ----------------------------------------------------- | --------- | ------ | -------------------------------------- |
| [id](./puppeteer.devicerequestpromptdevice.id.md) | | string | Device id during a prompt. |
| [name](./puppeteer.devicerequestpromptdevice.name.md) | | string | Device name as it appears in a prompt. |

View File

@ -0,0 +1,15 @@
---
sidebar_label: DeviceRequestPromptDevice.name
---
# DeviceRequestPromptDevice.name property
Device name as it appears in a prompt.
#### Signature:
```typescript
class DeviceRequestPromptDevice {
name: string;
}
```

View File

@ -30,7 +30,7 @@ class Frame {
**Returns:** **Returns:**
Promise&lt;DeviceRequestPrompt&gt; Promise&lt;[DeviceRequestPrompt](./puppeteer.devicerequestprompt.md)&gt;
## Example ## Example

View File

@ -30,7 +30,7 @@ class Page {
**Returns:** **Returns:**
Promise&lt;DeviceRequestPrompt&gt; Promise&lt;[DeviceRequestPrompt](./puppeteer.devicerequestprompt.md)&gt;
## Example ## Example

View File

@ -22,7 +22,7 @@ import {DeferredPromise} from '../util/DeferredPromise.js';
import {CDPSession} from './Connection.js'; import {CDPSession} from './Connection.js';
import {EventEmitter} from './EventEmitter.js'; import {EventEmitter} from './EventEmitter.js';
import {Frame} from './Frame.js'; import {FrameManager} from './FrameManager.js';
import {HTTPRequest} from './HTTPRequest.js'; import {HTTPRequest} from './HTTPRequest.js';
import {HTTPResponse} from './HTTPResponse.js'; import {HTTPResponse} from './HTTPResponse.js';
import {FetchRequestId, NetworkEventManager} from './NetworkEventManager.js'; import {FetchRequestId, NetworkEventManager} from './NetworkEventManager.js';
@ -68,20 +68,13 @@ export const NetworkManagerEmittedEvents = {
RequestFinished: Symbol('NetworkManager.RequestFinished'), RequestFinished: Symbol('NetworkManager.RequestFinished'),
} as const; } as const;
/**
* @internal
*/
interface FrameManager {
frame(frameId: string): Frame | null;
}
/** /**
* @internal * @internal
*/ */
export class NetworkManager extends EventEmitter { export class NetworkManager extends EventEmitter {
#client: CDPSession; #client: CDPSession;
#ignoreHTTPSErrors: boolean; #ignoreHTTPSErrors: boolean;
#frameManager: FrameManager; #frameManager: Pick<FrameManager, 'frame'>;
#networkEventManager = new NetworkEventManager(); #networkEventManager = new NetworkEventManager();
#extraHTTPHeaders: Record<string, string> = {}; #extraHTTPHeaders: Record<string, string> = {};
#credentials?: Credentials; #credentials?: Credentials;
@ -100,7 +93,7 @@ export class NetworkManager extends EventEmitter {
constructor( constructor(
client: CDPSession, client: CDPSession,
ignoreHTTPSErrors: boolean, ignoreHTTPSErrors: boolean,
frameManager: FrameManager frameManager: Pick<FrameManager, 'frame'>
) { ) {
super(); super();
this.#client = client; this.#client = client;

View File

@ -21,6 +21,7 @@ import {Protocol} from 'devtools-protocol';
import type {Browser} from '../api/Browser.js'; import type {Browser} from '../api/Browser.js';
import type {BrowserContext} from '../api/BrowserContext.js'; import type {BrowserContext} from '../api/BrowserContext.js';
import {ElementHandle} from '../api/ElementHandle.js'; import {ElementHandle} from '../api/ElementHandle.js';
import {HTTPRequest} from '../api/HTTPRequest.js';
import {HTTPResponse} from '../api/HTTPResponse.js'; import {HTTPResponse} from '../api/HTTPResponse.js';
import {JSHandle} from '../api/JSHandle.js'; import {JSHandle} from '../api/JSHandle.js';
import { import {
@ -61,7 +62,6 @@ import {
FrameWaitForFunctionOptions, FrameWaitForFunctionOptions,
} from './Frame.js'; } from './Frame.js';
import {FrameManager, FrameManagerEmittedEvents} from './FrameManager.js'; import {FrameManager, FrameManagerEmittedEvents} from './FrameManager.js';
import {HTTPRequest} from './HTTPRequest.js';
import {Keyboard, Mouse, MouseButton, Touchscreen} from './Input.js'; import {Keyboard, Mouse, MouseButton, Touchscreen} from './Input.js';
import {WaitForSelectorOptions} from './IsolatedWorld.js'; import {WaitForSelectorOptions} from './IsolatedWorld.js';
import {MAIN_WORLD} from './IsolatedWorlds.js'; import {MAIN_WORLD} from './IsolatedWorlds.js';

View File

@ -28,6 +28,7 @@ export * from './Coverage.js';
export * from './CustomQueryHandler.js'; export * from './CustomQueryHandler.js';
export * from './Debug.js'; export * from './Debug.js';
export * from './Device.js'; export * from './Device.js';
export * from './DeviceRequestPrompt.js';
export * from './Dialog.js'; export * from './Dialog.js';
export * from './ElementHandle.js'; export * from './ElementHandle.js';
export * from './EmulationManager.js'; export * from './EmulationManager.js';