block window.open
This commit is contained in:
parent
cf6978693d
commit
90b2e60c71
2 changed files with 23 additions and 9 deletions
|
@ -66,7 +66,7 @@
|
||||||
return undefined;
|
return undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
const keyPathToRefPath = function (keyPath) {
|
const keyPathToRefPath = function (keyPath, target) {
|
||||||
const keyParts = keyPath.split(".");
|
const keyParts = keyPath.split(".");
|
||||||
return keyParts.reduce(function (prev, cur) {
|
return keyParts.reduce(function (prev, cur) {
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@
|
||||||
|
|
||||||
const numNodes = prev.length;
|
const numNodes = prev.length;
|
||||||
const currentLeaf = (numNodes === 0)
|
const currentLeaf = (numNodes === 0)
|
||||||
? window
|
? target
|
||||||
: prev[numNodes - 1];
|
: prev[numNodes - 1];
|
||||||
const nextLeaf = currentLeaf[cur];
|
const nextLeaf = currentLeaf[cur];
|
||||||
|
|
||||||
|
@ -157,8 +157,10 @@
|
||||||
|
|
||||||
const defaultBlockingProxy = createBlockingProxy();
|
const defaultBlockingProxy = createBlockingProxy();
|
||||||
|
|
||||||
const blockFeatureAtKeyPath = function (keyPath) {
|
const blockFeatureAtKeyPath = function (keyPath, target) {
|
||||||
const propertyRefs = keyPathToRefPath(keyPath);
|
target = target || window;
|
||||||
|
|
||||||
|
const propertyRefs = keyPathToRefPath(keyPath, target);
|
||||||
|
|
||||||
// If we weren't able to turn the key path into an array of references,
|
// If we weren't able to turn the key path into an array of references,
|
||||||
// then it means that the property doesn't exist in this DOM /
|
// then it means that the property doesn't exist in this DOM /
|
||||||
|
@ -197,7 +199,20 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
featuresToBlock.forEach(blockFeatureAtKeyPath);
|
const oldWindowOpen = window.open;
|
||||||
|
const windowOpenProxy = new Proxy(window.open, {
|
||||||
|
apply: function (target, thisArg, argumentsList) {
|
||||||
|
console.log("window.open =", oldWindowOpen);
|
||||||
|
const wnd = oldWindowOpen.apply(thisArg, argumentsList);
|
||||||
|
featuresToBlock.forEach((v) => blockFeatureAtKeyPath(v, wnd));
|
||||||
|
return wnd;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Object.defineProperty(window, "open", {
|
||||||
|
get: () => windowOpenProxy
|
||||||
|
});
|
||||||
|
|
||||||
|
featuresToBlock.forEach((v) => blockFeatureAtKeyPath(v));
|
||||||
|
|
||||||
// Next, delete the WEB_API_MANAGER_PAGE global property. Technically
|
// Next, delete the WEB_API_MANAGER_PAGE global property. Technically
|
||||||
// this never needed to be global, but doing so allows for easier
|
// this never needed to be global, but doing so allows for easier
|
||||||
|
|
|
@ -189,7 +189,6 @@
|
||||||
"window.onvolumechange",
|
"window.onvolumechange",
|
||||||
"window.onwaiting",
|
"window.onwaiting",
|
||||||
"window.onwheel",
|
"window.onwheel",
|
||||||
"window.open",
|
|
||||||
"window.opener",
|
"window.opener",
|
||||||
"window.parent",
|
"window.parent",
|
||||||
"window.self",
|
"window.self",
|
||||||
|
|
Loading…
Add table
Reference in a new issue