summaryrefslogtreecommitdiffstats
path: root/dom/serviceworkers/test/serviceworker_not_sharedworker.js
blob: da0c98aea332413977196bf95a1bddbfa0cce449 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function OnMessage(e) {
  if (e.data.msg == "whoareyou") {
    if ("ServiceWorker" in self) {
      self.clients.matchAll().then(function (clients) {
        clients[0].postMessage({ result: "serviceworker" });
      });
    } else {
      port.postMessage({ result: "sharedworker" });
    }
  }
}

var port;
onconnect = function (e) {
  port = e.ports[0];
  port.onmessage = OnMessage;
  port.start();
};

onmessage = OnMessage;