| Index: lib/content/snippets.js |
| =================================================================== |
| --- a/lib/content/snippets.js |
| +++ b/lib/content/snippets.js |
| @@ -408,8 +408,54 @@ |
| mutation.target.appendChild(node); |
| } |
| } |
| } |
| }); |
| } |
| exports.readd = readd; |
| + |
| +function randomId() |
| +{ |
| + // 2176782336 is 36^6 which mean 6 chars [a-z0-9] |
| + return Math.floor(Math.random() * 2176782336).toString(36); |
| +} |
| + |
| +/** |
| + * Will patch a property on the window object to abort when read. |
| + * It will intercept the onerror callback and block it if tagged. |
| + * |
| + * @todo handle properties of properties. |
| + * |
| + * @param {string} the name of the property |
| + */ |
| +function abortOnPropertyRead(prop) |
| +{ |
| + if (!prop) |
| + return; |
| + |
| + let magic = randomId(); |
| + |
| + let abort = function() { |
| + throw new ReferenceError(magic); |
| + }; |
| + |
| + let onerror = window.onerror; |
| + window.onerror = (msg, ...args) => |
| + { |
| + if (typeof msg === "string" && msg.indexOf(magic) != -1) |
| + return true; |
| + if (onerror) |
| + return onerror(msg, ...args); |
| + }; |
| + |
| + // patching function |
| + (function (o, p) { |
| + // simple property |
| + let d = Object.getOwnPropertyDescriptor(o, p); |
| + if (!d || d.get !== abort) { |
| + Object.defineProperty(o, p, { get: abort, set: () => {}}); |
| + } |
| + })(window, prop); |
| +} |
| + |
| +exports["abort-on-property-read"] = makeInjector(abortOnPropertyRead, randomId); |