blob: 00f6acede8eb4fafbbf6a248c75db84dba3efc40 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
<!DOCTYPE html>
<html>
<script>
// Return a URL of a client when it's successful.
function createAndFetchFromBlobWorker() {
const fetchURL = new URL('get-worker-client-url.txt', window.location).href;
const workerScript =
`self.onmessage = async (e) => {
const response = await fetch(e.data.url);
const text = await response.text();
self.postMessage({"result": text, "expected": self.location.href});
};`;
const blob = new Blob([workerScript], { type: 'text/javascript' });
const blobUrl = URL.createObjectURL(blob);
const worker = new Worker(blobUrl);
return new Promise((resolve, reject) => {
worker.onmessage = e => resolve(e.data);
worker.onerror = e => reject(e.message);
worker.postMessage({"url": fetchURL});
});
}
</script>
</html>
|