summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webusb/resources/open-in-worker.js
blob: e16621057a0240186803bb1de1c012406c89505d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
importScripts('/resources/test-only-api.js');
importScripts('/webusb/resources/usb-helpers.js');
'use strict';

onmessage = messageEvent => {
  if (messageEvent.data.type === 'Ready') {
    navigator.usb.addEventListener('connect', connectEvent => {
      connectEvent.device.open().then(() => {
        postMessage({ type: 'Success' });
      }).catch(error => {
        postMessage({ type: `FAIL: open rejected ${error}` });
      });
    });
    postMessage({ type: 'Ready' });
  }
};