function getCustomWindowProps() {
const iframe = document.createElement("iframe");
document.documentElement.appendChild(iframe);
const _window = iframe.contentWindow;
document.documentElement.removeChild(iframe);
const origWindowProps = new Set(Object.getOwnPropertyNames(_window));
return Object.getOwnPropertyNames(window).filter(prop => !origWindowProps.has(prop));
}
This uses a trick of adding an empty iframe (need to add it temporarily to document so that its contentWindow
is initialized...), then comparing current window
with that one. This will in allow you to return only custom props added on top of current window
, skipping whatever was defined by your browsers and its extensions.
For example for StackOverflow, this will currently return:
["$", "jQuery", "StackExchange", "StackOverflow", "__tr", "jQuery3710271175959070636961", "gtag", "dataLayer", "ga", "cam", "clcGamLoaderOptions", "opt", "googletag", "Stacks", "webpackChunkstackoverflow", "__svelte", "klass", "moveScroller", "styleCode", "initTagRenderer", "UniversalAuth", "Svg", "tagRendererRaw", "tagRenderer", "siteIncludesLoaded", "hljs", "apiCallbacks", "Commonmark", "markdownit"]