Created
January 16, 2018 20:39
-
-
Save farskid/cc9600f9b5518be9d88a6cc25c403632 to your computer and use it in GitHub Desktop.
Find out global variables added by scripts on a website
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
/* | |
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)); |
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
/* | |
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