[demo][normalize.js] TypeError: Illegal invocation for window property within with statement on Object.create(window)
Root Cause
Some global properties such as window that is not invoked for the global object as this is TypeError: Illegal invocation
May not be reproducible with older Chrome browsers
Reproducible Code
with (Object.create(window)) {
chai.assert.throws(() => {
caches;
}, /^Permission Denied:/);
chai.assert.throws(() => {
Object.getOwnPropertyDescriptor(window, 'caches'); // access to window is illegal
}, /^Permission Denied:/);
}
Fix
As the code in normalize.js is for trying to circumventing proper application of thin-hook access policies, working trials should be used instead of non-working illegal access.
In contrast to window global property with its dedicated getter function, globalThis is a simple global property without a getter function.
Define an alias local variable window with the value of globalThis
diff --git a/demo-raw/normalize.js b/demo-raw/normalize.js
index 0d74370e..dcf2b00c 100644
--- a/demo-raw/normalize.js
+++ b/demo-raw/normalize.js
@@ -722,6 +722,7 @@
}
with (Object.create(window)) {
[demo][normalize.js] TypeError: Illegal invocation for window property within
with
statement on Object.create(window)Root Cause
window
that is not invoked for the global object asthis
isTypeError: Illegal invocation
Reproducible Code
Fix
normalize.js
is for trying to circumventing proper application of thin-hook access policies, working trials should be used instead of non-working illegal access.window
global property with its dedicated getter function,globalThis
is a simple global property without a getter function.Define an alias local variable
window
with the value ofglobalThis