Skip to content

Commit

Permalink
Improve spoof-css scriptlet
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Mar 2, 2024
1 parent a086ae1 commit 6032399
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions assets/resources/scriptlets.js
Expand Up @@ -3568,6 +3568,11 @@ function spoofCSS(
}
return value;
};
const cloackFunc = (fn, thisArg, name) => {
const trap = fn.bind(thisArg);
Object.defineProperty(trap, 'name', { value: name });
return trap;
};
self.getComputedStyle = new Proxy(self.getComputedStyle, {
apply: function(target, thisArg, args) {
if ( shouldDebug !== 0 ) { debugger; } // jshint ignore: line
Expand All @@ -3578,11 +3583,11 @@ function spoofCSS(
get(target, prop, receiver) {
if ( typeof target[prop] === 'function' ) {
if ( prop === 'getPropertyValue' ) {
return (function(prop) {
return cloackFunc(function(prop) {
return spoofStyle(prop, target[prop]);
}).bind(target);
}, target, 'getPropertyValue');
}
return target[prop].bind(target);
return cloackFunc(target[prop], target, prop);
}
return spoofStyle(prop, Reflect.get(target, prop, receiver));
},
Expand Down

0 comments on commit 6032399

Please sign in to comment.