Updated a few more things

This commit is contained in:
QuiteAFancyEmerald 2022-02-08 00:43:17 -08:00
parent c827e9f7e1
commit 73cdcb3186
47 changed files with 35805 additions and 1102 deletions

45
lib/browser/iframe.js Normal file
View file

@ -0,0 +1,45 @@
const { overrideAccessors } = require("./utils");
function createIframeRewriter(ctx) {
if (ctx.serviceWorker) return () => null;
const {
HTMLIFrameElement
} = ctx.window;
function rewriteContentDocument() {
overrideAccessors(HTMLIFrameElement.prototype, 'contentDocument', {
getter: (target, that) => {
const doc = target.call(that);
try {
if (!doc.defaultView.$corrosion) initCorrosion(doc.defaultView);
return doc;
} catch(e) {
return doc;
};
},
});
};
function rewriteContentWindow() {
overrideAccessors(HTMLIFrameElement.prototype, 'contentWindow', {
getter: (target, that) => {
const win = target.call(that);
try {
if (!win.$corrosion) initCorrosion(win);
return win;
} catch(e) {
return win;
};
},
});
};
function initCorrosion(win) {
win.$corrosion = new ctx.constructor({ ...ctx.config, window: win, });
win.$corrosion.init();
win.$corrosion.meta = ctx.meta;
};
return function rewriteIframe() {
rewriteContentWindow();
rewriteContentDocument();
};
};
module.exports = createIframeRewriter;