Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Puppeteer Puppeteer DeviceRequestPrompt

From Leeroopedia
Sources packages/puppeteer-core/src/api/DeviceRequestPrompt.ts
Domains Device Selection, Web Bluetooth, User Prompts
Last Updated 2026-02-12

Overview

DeviceRequestPrompt is the abstract base class that represents a browser device request prompt, allowing programmatic interaction with device selection dialogs triggered by APIs such as Web Bluetooth.

Description

The DeviceRequestPrompt class models the browser-native device selection dialog that appears when a page requests access to a hardware device through APIs like Web Bluetooth. The class maintains a devices read-only array of DeviceRequestPromptDevice objects, each containing an id string and a name string representing a selectable device in the prompt.

The class provides three abstract methods for interacting with the prompt. The waitForDevice() method resolves to the first device in the prompt that matches a given filter function, with optional timeout configuration via WaitTimeoutOptions. The select() method chooses a specific device from the prompt's list, completing the device request. The cancel() method dismisses the prompt without selecting a device.

The DeviceRequestPromptDevice interface, also exported from this module, defines the shape of individual device entries with id and name fields.

Usage

DeviceRequestPrompt instances are obtained through Page.waitForDevicePrompt(). A typical workflow involves calling waitForDevicePrompt() concurrently with an action that triggers the device prompt (such as clicking a "connect" button), then using waitForDevice() to find the desired device and select() to choose it.

Code Reference

Source Location

packages/puppeteer-core/src/api/DeviceRequestPrompt.ts

Signature

export interface DeviceRequestPromptDevice {
  id: string;
  name: string;
}

export abstract class DeviceRequestPrompt {
  readonly devices: DeviceRequestPromptDevice[];
  abstract waitForDevice(
    filter: (device: DeviceRequestPromptDevice) => boolean,
    options?: WaitTimeoutOptions,
  ): Promise<DeviceRequestPromptDevice>;
  abstract select(device: DeviceRequestPromptDevice): Promise<void>;
  abstract cancel(): Promise<void>;
}

Import

import type {DeviceRequestPrompt, DeviceRequestPromptDevice} from 'puppeteer-core/src/api/DeviceRequestPrompt.js';

I/O Contract

Inputs

Parameter Type Description
filter (waitForDevice) (device: DeviceRequestPromptDevice) => boolean Predicate function to match a device by its properties
options (waitForDevice) WaitTimeoutOptions Optional timeout configuration for waiting
device (select) DeviceRequestPromptDevice The device to select from the prompt's list

Outputs

Method Return Type Description
devices DeviceRequestPromptDevice[] Current list of selectable devices in the prompt
waitForDevice() Promise<DeviceRequestPromptDevice> The first device matching the filter
select() Promise<void> Resolves when the device has been selected
cancel() Promise<void> Resolves when the prompt has been cancelled

Usage Examples

// Wait for and interact with a device request prompt
const [devicePrompt] = await Promise.all([
  page.waitForDevicePrompt(),
  page.click('#connect-bluetooth'),
]);
await devicePrompt.select(
  await devicePrompt.waitForDevice(({name}) => name.includes('My Device')),
);
// Cancel a device request prompt
const [devicePrompt] = await Promise.all([
  page.waitForDevicePrompt(),
  page.click('#connect-bluetooth'),
]);
await devicePrompt.cancel();
// List available devices in the prompt
const [devicePrompt] = await Promise.all([
  page.waitForDevicePrompt(),
  page.click('#connect-bluetooth'),
]);
for (const device of devicePrompt.devices) {
  console.log(`Device: ${device.name} (${device.id})`);
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment