Fix Worker conflict detection #294
This commit is contained in:
@@ -25,6 +25,19 @@ twitch-videoad.js text/javascript
|
||||
}
|
||||
var twitchWorkers = [];
|
||||
const oldWorker = window.Worker;
|
||||
function isWorkerDoubleHooked(ourWorker, identifier) {
|
||||
var ourWorkerString = ourWorker ? ourWorker.toString() : null;
|
||||
var proto = window.Worker;
|
||||
while (proto)
|
||||
{
|
||||
var workerString = proto.toString();
|
||||
if (workerString.includes(identifier) && workerString !== ourWorkerString) {
|
||||
return true;
|
||||
}
|
||||
proto = Object.getPrototypeOf(proto);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function hookWindowWorker() {
|
||||
var newWorker = window.Worker = class Worker extends oldWorker {
|
||||
constructor(twitchBlobUrl, options) {
|
||||
@@ -32,7 +45,7 @@ twitch-videoad.js text/javascript
|
||||
try {
|
||||
isTwitchWorker = new URL(twitchBlobUrl).origin.endsWith('.twitch.tv');
|
||||
} catch {}
|
||||
if (newWorker.toString() !== window.Worker.toString()) {
|
||||
if (isWorkerDoubleHooked(newWorker, 'twitch')) {
|
||||
console.log('Multiple twitch adblockers installed. Skipping Worker hook (video-swap-new)');
|
||||
isTwitchWorker = false;
|
||||
}
|
||||
@@ -653,8 +666,8 @@ twitch-videoad.js text/javascript
|
||||
return realGetItem.apply(this, arguments);
|
||||
};
|
||||
}
|
||||
if (window.Worker.toString().includes('twitch')) {
|
||||
console.log('Twitch Worker is already hooked');
|
||||
if (isWorkerDoubleHooked(null, 'twitch')) {
|
||||
console.log('Twitch Worker is already hooked. Skipping (video-swap-new)');
|
||||
} else {
|
||||
window.reloadTwitchPlayer = reloadTwitchPlayer;
|
||||
declareOptions(window);
|
||||
|
||||
Reference in New Issue
Block a user