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 Cdp DeviceRequestPrompt

From Leeroopedia
Property Value
sources packages/puppeteer-core/src/cdp/DeviceRequestPrompt.ts
domains CDP, Device Access, Prompts
last_updated 2026-02-12 00:00 GMT

Overview

Description

The Cdp DeviceRequestPrompt module provides the CDP-specific implementation for handling device request prompts, such as those triggered by the Web Bluetooth or WebUSB APIs. It contains two classes:

  • CdpDeviceRequestPrompt -- Extends the abstract DeviceRequestPrompt base class. It listens for DeviceAccess.deviceRequestPrompted CDP events to populate its device list, and provides methods to waitForDevice(), select() a device, or cancel() the prompt. Each method interacts with the CDP session via DeviceAccess.selectPrompt or DeviceAccess.cancelPrompt.
  • CdpDeviceRequestPromptManager -- Manages the lifecycle of device request prompts. It listens for DeviceAccess.deviceRequestPrompted events and resolves deferred promises that were set up by waitForDevicePrompt(). It lazily enables the DeviceAccess domain only when a wait is active.

Both classes handle session detachment gracefully by nullifying the client reference when Target.detachedFromTarget is received.

Usage

The CdpDeviceRequestPromptManager is instantiated per-page in the CDP page implementation. Users interact with it through page.waitForDevicePrompt(), which returns a DeviceRequestPrompt instance on which they can wait for, select, or cancel devices.

Code Reference

Source Location

packages/puppeteer-core/src/cdp/DeviceRequestPrompt.ts (230 lines)

Signature

export class CdpDeviceRequestPrompt extends DeviceRequestPrompt {
  constructor(
    client: CDPSession,
    timeoutSettings: TimeoutSettings,
    firstEvent: Protocol.DeviceAccess.DeviceRequestPromptedEvent,
  );
  async waitForDevice(
    filter: (device: DeviceRequestPromptDevice) => boolean,
    options?: WaitTimeoutOptions,
  ): Promise<DeviceRequestPromptDevice>;
  async select(device: DeviceRequestPromptDevice): Promise<void>;
  async cancel(): Promise<void>;
}

export class CdpDeviceRequestPromptManager {
  constructor(client: CDPSession, timeoutSettings: TimeoutSettings);
  async waitForDevicePrompt(
    options?: WaitTimeoutOptions,
  ): Promise<DeviceRequestPrompt>;
}

Import

import { CdpDeviceRequestPrompt, CdpDeviceRequestPromptManager } from '../cdp/DeviceRequestPrompt.js';

I/O Contract

CdpDeviceRequestPrompt.waitForDevice

Direction Name Type Description
Input filter (device: DeviceRequestPromptDevice) => boolean Predicate to match a specific device
Input options WaitTimeoutOptions Optional timeout and abort signal
Output result Promise<DeviceRequestPromptDevice> The matching device
Error TimeoutError Error Thrown if the timeout is exceeded

CdpDeviceRequestPrompt.select

Direction Name Type Description
Input device DeviceRequestPromptDevice The device to select from the prompt
Output result Promise<void> Resolves when the device is selected via CDP
Error AssertionError Error Thrown if session is detached, device is unknown, or prompt is already handled

CdpDeviceRequestPromptManager.waitForDevicePrompt

Direction Name Type Description
Input options WaitTimeoutOptions Optional timeout and abort signal
Output result Promise<DeviceRequestPrompt> The device request prompt instance
Error AssertionError Error Thrown if the session is detached
Error TimeoutError Error Thrown if the timeout is exceeded

Usage Examples

// Wait for a device request prompt and select a Bluetooth device
const promptPromise = page.waitForDevicePrompt();

// Trigger a Bluetooth request on the page
await page.click('#connect-bluetooth');

const prompt = await promptPromise;

// Wait for a specific device to appear
const device = await prompt.waitForDevice(d => d.name.includes('My Device'));

// Select the device
await prompt.select(device);

// Or cancel the prompt
// await prompt.cancel();

Related Pages

Page Connections

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