Skip to content

Instantly share code, notes, and snippets.

@farskid
Created January 16, 2018 20:39
Show Gist options
  • Save farskid/cc9600f9b5518be9d88a6cc25c403632 to your computer and use it in GitHub Desktop.
Save farskid/cc9600f9b5518be9d88a6cc25c403632 to your computer and use it in GitHub Desktop.
Find out global variables added by scripts on a website
/*
Method1: Create an iframe and compare it's window object with website's window
*/
const iframe = document.createElement('iframe');
document.body.append(iframe);
const virgin = Object.keys(iframe.contentWindow);
const current = Object.keys(window);
const added = current.filter(key => !virgin.includes(key));
/*
Method2: By creating a new window and comparing it's window object with our current window
*/
const newWindow = window.open();
const added = Object.keys(newWindow).filter(key => !newWindow.hasOwnProperty(key));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment