Browse Source

fix: getWindowLength for Chrome<=85

tophf 3 years ago
parent
commit
d2a40457f6

+ 3 - 2
src/injected/safe-globals-injected.js

@@ -29,11 +29,12 @@ export const isFunction = val => typeof val === 'function';
 export const isObject = val => val != null && typeof val === 'object';
 export const isString = val => typeof val === 'string';
 
-export const getOwnProp = (obj, key) => {
+export const getOwnProp = (obj, key, defVal) => {
   // obj may be a Proxy that throws in has() or its getter throws
   try {
-    if (obj::hasOwnProperty(key)) return obj[key];
+    if (obj::hasOwnProperty(key)) defVal = obj[key];
   } catch (e) { /* NOP */ }
+  return defVal;
 };
 
 /** Workaround for array eavesdropping via prototype setters like '0','1',...

+ 2 - 2
src/injected/web/gm-global-wrapper.js

@@ -255,8 +255,8 @@ function makeOwnKeys(local, globals) {
   const names = getOwnPropertyNames(local)::filter(notIncludedIn, globals);
   const symbols = getOwnPropertySymbols(local)::filter(notIncludedIn, globals);
   const frameIndexes = [];
-  for (let i = 0, len = window::getWindowLength(); i < len; i += 1) {
-    if (!(i in local) && window::hasOwnProperty(i)) {
+  for (let i = 0, len = window::getWindowLength(); i < len && window::hasOwnProperty(i); i += 1) {
+    if (!(i in local)) {
       setOwnProp(frameIndexes, i, i);
     }
   }

+ 2 - 1
src/injected/web/safe-globals-web.js

@@ -167,7 +167,8 @@ export const VAULT = (() => {
     getCurrentScript = res[i += 1] || describeProperty(src.Document[PROTO], 'currentScript').get,
     getDetail = res[i += 1] || describeProperty(SafeCustomEvent[PROTO], 'detail').get,
     getRelatedTarget = res[i += 1] || describeProperty(SafeMouseEvent[PROTO], 'relatedTarget').get,
-    getWindowLength = res[i += 1] || describeProperty(src, 'length').get,
+    getWindowLength = res[i += 1] || describeProperty(src, 'length').get
+      || (() => getOwnProp(window, 'length', 1e9)), // Chrome<=85 https://crrev.com/793165
     // various values
     builtinGlobals = res[i += 1] || [
       getOwnPropertyNames(srcWindow),