Last active
February 18, 2019 16:33
-
-
Save emileber/00bd96b411f39cb893142a41e4a7e5cf to your computer and use it in GitHub Desktop.
Check for globals added by other scripts after the page is loaded.
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
/** | |
* Check for globals added by other scripts after the page is loaded. | |
* Place this at the top of `<head>`. | |
* | |
* Uses `getOwnPropertyNames` to get the non-enumerable properties as well. | |
*/ | |
(function(getGlobalKeys) { | |
var keys = getGlobalKeys(); | |
window.addEventListener("load", function() { | |
var diff = getGlobalKeys().filter(function(key) { | |
return keys.indexOf(key) === -1; | |
}); | |
console.log( | |
"Unusual globals (%d): %o", | |
diff.length, | |
diff.reduce(function(win, key) { | |
win[key] = window[key]; | |
return win; | |
}, {}) | |
); | |
}); | |
})(function() { | |
return Object.getOwnPropertyNames(window); | |
}); |
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
/** | |
* Check for globals added by other scripts after the page is loaded. | |
* Place this at the top of `<head>`. | |
* | |
* Uses `getOwnPropertyNames` to get the non-enumerable properties as well. | |
*/ | |
((getGlobalKeys) => { | |
const keys = getGlobalKeys(); | |
window.addEventListener("load", () => { | |
const diff = getGlobalKeys().filter(key => keys.indexOf(key) === -1); | |
console.log( | |
"Unusual globals (%d): %o", | |
diff.length, | |
diff.reduce((win, key) => { | |
win[key] = window[key]; | |
return win; | |
}, {}) | |
); | |
}); | |
})(() => Object.getOwnPropertyNames(window)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment