Puppeteer 中文文档v25.8.0

BluetoothEmulation 接口

暴露蓝牙模拟能力。

签名

export interface BluetoothEmulation

备注

Web Bluetooth 规范要求模拟适配器应在每个顶层可导航单元中相互隔离。然而,目前 Chromium 的蓝牙模拟实现与浏览器上下文绑定,而非页面。这意味着来自同一浏览器上下文的不同页面所暴露的蓝牙模拟会互相干扰彼此的状态。

示例

await page.bluetooth.emulateAdapter('powered-on');
await page.bluetooth.simulatePreconnectedPeripheral({
  address: '09:09:09:09:09:09',
  name: 'SOME_NAME',
  manufacturerData: [
    {
      key: 17,
      data: 'AP8BAX8=',
    },
  ],
  knownServiceUuids: ['12345678-1234-5678-9abc-def123456789'],
});
await page.bluetooth.disableEmulation();

方法

方法

说明

disableEmulation()

(实验性) 禁用模拟的蓝牙适配器。参见 bluetooth.disableSimulation

emulateAdapter(state, leSupported)

(实验性) 模拟蓝牙适配器。蓝牙模拟所必需。参见 bluetooth.simulateAdapter

simulatePreconnectedPeripheral(preconnectedPeripheral)

(实验性) 模拟已预连接的蓝牙外设。参见 bluetooth.simulatePreconnectedPeripheral