Reputation: 704
I have a bookmarklet that makes use of the window.open method.
Sometimes websites modify this method so I cannot predict the behaviour of running the bookmarklet.
Is there any way to get an "untouched" window object?
I tried injecting a new iframe and getting the window object from this but then chrome is blocking the popup (see https://bugs.chromium.org/p/chromium/issues/detail?id=932884).
window.open("http://example.com");
Upvotes: 0
Views: 83
Reputation: 91525
You can check if the window.open
method is native code or not by using .toString()
and checking if [native code]
is present.
window.open.toString()
// returns: "function open() { [native code] }"
window.open.toString().includes('[native code]')
// returns: true
window.open = function() { console.log('ding!'); }
window.open.toString().includes('[native code]')
// returns: false
Additionally, you can reasonably ensure .toString()
hasn't been overridden by calling it from the prototype.
Function.prototype.toString.call(window.open).includes('[native code]')
Upvotes: 1