Skip to content

Instantly share code, notes, and snippets.

@zacharytamas
Created June 13, 2014 19:24
Show Gist options
  • Save zacharytamas/082e538784ebe07e40f9 to your computer and use it in GitHub Desktop.
Save zacharytamas/082e538784ebe07e40f9 to your computer and use it in GitHub Desktop.
Override window.location
(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'
}());
}());
@ohpyupi
Copy link

ohpyupi commented Jul 2, 2019

Uncaught TypeError: Immutable prototype object '#<Window>' cannot have their prototype set
    at set __proto__ (<anonymous>)
    at <anonymous>:1:18

@puppeteer701vungle
Copy link

I get the same issue

@zacharytamas
Copy link
Author

@ohpyupi @puppeteer701vungle This snippet is from six years ago and new security rules in browsers prevent this approach from working now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment