summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webusb/resources/open-in-worker.js
blob: 2175cfd39787ada1a48b74c1a8e6ead56d626c2a (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 === 'ConnectEvent') {
    navigator.usb.addEventListener('connect', connectEvent => {
      connectEvent.device.open().then(() => {
        postMessage({ type: 'Success' });
      }).catch(error => {
        postMessage({ type: `FAIL: open rejected ${error}` });
      });
    });
    postMessage({ type: 'Ready' });
  }
};