Created
June 13, 2014 19:24
-
-
Save zacharytamas/082e538784ebe07e40f9 to your computer and use it in GitHub Desktop.
Override window.location
This file contains 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
(function () { | |
var _window = window; | |
(function () { | |
var window = {}; | |
Object.defineProperty(window, 'location', { | |
get: function () { return _window.location; }, | |
set: function () { alert('not in my house'); } | |
}); | |
window.__proto__ = _window; | |
// At this point, 'window' is identical to normal window except | |
// we've overriden its location property to be read-only. | |
// If you could manage to run your page's environment here, you could | |
// intercept attempts to change the page. | |
window.location = "blah"; // alerts 'not in my house' | |
}()); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ohpyupi @puppeteer701vungle This snippet is from six years ago and new security rules in browsers prevent this approach from working now.