Last active
April 27, 2025 10:28
-
-
Save alpgul/c9f306dc16640f3f79b808c343d5624f to your computer and use it in GitHub Desktop.
Advanced Window Proxy with Recursive Proxying
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(() => { | |
const proxyCache = new WeakMap(); | |
const get = Reflect.get; | |
const set = Reflect.get; | |
const log = console.log; | |
const windowProxyHandler = { | |
get(target, property) { | |
log(`Getting property: ${String(property)}`); | |
const value = get(target, property); | |
if (typeof value === 'function') { | |
return function (...args) { | |
return value.apply(target, args); | |
}; | |
} | |
if (value !== null && typeof value === 'object') { | |
if (proxyCache.has(value)) return proxyCache.get(value); | |
const proxy = new Proxy(value, windowProxyHandler); | |
proxyCache.set(value, proxy); | |
return proxy; | |
} | |
return value; | |
}, | |
set(target, property, value) { | |
log(`Setting property: ${String(property)} to`, value); | |
return set(target, property, value); | |
} | |
}; | |
// Tüm global property'leri al | |
const globalProps = [ | |
...Object.getOwnPropertyNames(globalThis), | |
...Object.getOwnPropertySymbols(globalThis) | |
]; | |
for (const property of globalProps) { | |
let value; | |
try { | |
value = globalThis[property]; | |
} catch (e) { | |
console.warn(`Cannot access globalThis.${String(property)}: ${e.message}`); | |
continue; | |
} | |
if (value !== null && (typeof value === 'object')) { | |
var proxy = proxyCache.has(value) ? proxyCache.get(value) : new Proxy(value, windowProxyHandler); | |
if (!proxyCache.has(value)) proxyCache.set(value, proxy); | |
const descriptor = Object.getOwnPropertyDescriptor(globalThis, property); | |
if (!descriptor || descriptor.configurable) { | |
Object.defineProperty(globalThis, property, { | |
value: proxy, | |
writable: true, | |
configurable: true, | |
}); | |
console.log(`${String(property)}:`, globalThis[property]); | |
} else { | |
console.warn(`Property ${String(property)} is non-configurable, trying eval...`); | |
try { | |
if (typeof property === 'string' && /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(property)) { | |
eval(`var ${property} = proxy;`); | |
eval(`console.log("${property}:", ${property})`); | |
} else { | |
console.warn(`Skipping eval for non-string or invalid property name: ${String(property)}`); | |
} | |
} catch (evalError) { | |
console.error(`Eval failed for ${String(property)}: ${evalError.message}`); | |
} | |
} | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment