Skip to content

Commit

Permalink
Hook attachShadow
Browse files Browse the repository at this point in the history
Fixes #5
  • Loading branch information
NDevTK authored Dec 30, 2024
1 parent f810056 commit 2e34d04
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions WindowScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,28 @@
}

document.querySelectorAll('iframe').forEach(hookIframe);
new MutationObserver(async records => {
for (let record of records) {
for (let node of record.addedNodes) {
if (node.tagName === 'IFRAME') {
hookIframe(node);

function iframeFinder(doc) {
new MutationObserver(async records => {
for (let record of records) {
for (let node of record.addedNodes) {
if (node.tagName === 'IFRAME') {
hookIframe(node);
}
}
}
}
}).observe(document.documentElement, {childList: true, subtree: true});
}).observe(doc, {childList: true, subtree: true});
}

iframeFinder(document.documentElement);

const attachShadow = Element.prototype.attachShadow;
Element.prototype.attachShadow = function(options) {
const shadowRoot = attachShadow.call(this, options);
iframeFinder(shadowRoot);
return shadowRoot;
};

function handle(type, iframe) {
return {
get: function(target, property) {
Expand Down

0 comments on commit 2e34d04

Please sign in to comment.