1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
content / test / data / browsing_data / shared_worker.js [blame]
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
let clients = new Array();
let value = null;
// This shared worker allows to store and retrieve values across tabs.
self.onconnect = e => {
let port = e.ports[0];
clients.push(port);
port.onmessage = e => {
if (e.data.value) {
value = e.data.value;
} else {
for (let client of clients)
client.postMessage({ "value": value });
}
};
port.start();
port.postMessage({ "connected": true });
};