Fix up context check

This commit is contained in:
Mario Zechner 2025-10-11 21:41:24 +02:00
parent 8a96741441
commit 63bfe95c18
5 changed files with 19 additions and 29 deletions

View file

@ -559,14 +559,18 @@ ${runtimeFunctions.join("\n")}
}
}, true);
// Prevent window.location changes
const originalLocation = window.location;
Object.defineProperty(window, 'location', {
get: function() { return originalLocation; },
set: function(url) {
window.parent.postMessage({ type: 'open-external-url', url: url.toString() }, '*');
}
});
// Prevent window.location changes (only if not already redefined)
try {
const originalLocation = window.location;
Object.defineProperty(window, 'location', {
get: function() { return originalLocation; },
set: function(url) {
window.parent.postMessage({ type: 'open-external-url', url: url.toString() }, '*');
}
});
} catch (e) {
// Already defined, skip
}
})();
</script>`;
}