mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-12-22 12:50:36 +01:00
parent
308d7c4005
commit
49f3c166a2
@ -67,19 +67,48 @@ iframeAPI.forEachMethod(function(windowToUse, name){
|
||||
processNavigatorObject(navigator, Object.keys(navigator.__proto__), name);
|
||||
});
|
||||
|
||||
const worker = new Worker("navigatorTestWorker.js");
|
||||
function processWorkerNavigatorObject(data, name){
|
||||
"use strict";
|
||||
processNavigatorObject(data.values, Object.keys(data.values), name);
|
||||
if (data.nestedValues){
|
||||
processWorkerNavigatorObject(data.nestedValues, "nested " + name);
|
||||
}
|
||||
}
|
||||
|
||||
const worker = new Worker("navigatorTestWorker.js", {name: "Worker"});
|
||||
worker.addEventListener("message", function(event){
|
||||
"use strict";
|
||||
|
||||
processNavigatorObject(event.data, Object.keys(event.data), "Worker");
|
||||
processWorkerNavigatorObject(event.data, "Worker");
|
||||
worker.terminate();
|
||||
});
|
||||
|
||||
const sharedWorker = new SharedWorker("navigatorTestWorker.js");
|
||||
fetch("navigatorTestWorker.js").then(function(response){
|
||||
"use strict";
|
||||
|
||||
return response.text();
|
||||
}).then(function(code){
|
||||
"use strict";
|
||||
|
||||
const blob = new Blob([code], {type: "text/javascript"});
|
||||
const blobWorker = new Worker(URL.createObjectURL(blob), {name: "BlobWorker"});
|
||||
blobWorker.addEventListener("message", function(event){
|
||||
processWorkerNavigatorObject(event.data, "BlobWorker");
|
||||
blobWorker.terminate();
|
||||
});
|
||||
|
||||
return blobWorker;
|
||||
}).catch(function(error){
|
||||
"use strict";
|
||||
|
||||
console.error("Unable to create BlobWorker:", error);
|
||||
});
|
||||
|
||||
const sharedWorker = new SharedWorker("navigatorTestWorker.js", {name: "SharedWorker"});
|
||||
sharedWorker.port.addEventListener("message", function(event){
|
||||
"use strict";
|
||||
|
||||
processNavigatorObject(event.data, Object.keys(event.data), "SharedWorker");
|
||||
processWorkerNavigatorObject(event.data, "SharedWorker");
|
||||
sharedWorker.port.close();
|
||||
});
|
||||
sharedWorker.port.start();
|
||||
@ -89,7 +118,7 @@ navigator.serviceWorker.register("navigatorTestWorker.js").then(function(registr
|
||||
|
||||
const worker = (registration.active || registration.waiting || registration.installing);
|
||||
navigator.serviceWorker.addEventListener("message", function(event){
|
||||
processNavigatorObject(event.data, Object.keys(event.data), "ServiceWorker");
|
||||
processWorkerNavigatorObject(event.data, "ServiceWorker");
|
||||
registration.unregister();
|
||||
});
|
||||
if (worker.state !== "activated"){
|
||||
|
@ -2,6 +2,7 @@
|
||||
"use strict";
|
||||
|
||||
const values = {};
|
||||
let nestedValues = false;
|
||||
const navigator = self.navigator;
|
||||
Object.keys(navigator.__proto__).sort().forEach(function(property){
|
||||
const value = navigator[property];
|
||||
@ -9,16 +10,49 @@
|
||||
values[property] = value;
|
||||
}
|
||||
});
|
||||
|
||||
const ports = [];
|
||||
const sources = [];
|
||||
let sendDelayed = false;
|
||||
function sendData(){
|
||||
sendDelayed = true;
|
||||
if (self.postMessage){
|
||||
self.postMessage(values);
|
||||
self.postMessage({values, nestedValues});
|
||||
}
|
||||
ports.forEach(function(port){
|
||||
port.postMessage({values, nestedValues});
|
||||
});
|
||||
sources.forEach(function(source){
|
||||
source.postMessage({values, nestedValues});
|
||||
});
|
||||
}
|
||||
self.addEventListener("connect", function(event){
|
||||
event.ports.forEach(function(port){
|
||||
port.postMessage(values);
|
||||
ports.push(port);
|
||||
});
|
||||
if (sendDelayed){
|
||||
sendData();
|
||||
}
|
||||
});
|
||||
self.addEventListener("message", function(event){
|
||||
event.source.postMessage(values);
|
||||
return values;
|
||||
sources.push(event.source);
|
||||
if (sendDelayed){
|
||||
sendData();
|
||||
}
|
||||
});
|
||||
|
||||
if (
|
||||
!(self.name && self.name.startsWith("nested nested")) &&
|
||||
self.Worker
|
||||
){
|
||||
const worker = new Worker(self.location, {name: "nested " + (self.name || "")});
|
||||
worker.addEventListener("message", function(event){
|
||||
nestedValues = event.data;
|
||||
worker.terminate();
|
||||
sendData();
|
||||
});
|
||||
}
|
||||
else {
|
||||
sendData();
|
||||
}
|
||||
}());
|
Loading…
x
Reference in New Issue
Block a user