Overwriting Native Methods in Javascript

I am analyzing some Javascript, and I want to enable javascript, but disable all alert () blocks and self.location redirects.

I am currently using regex proxy, but it seems like overkill.

I can override some native methods, but not others in Firefox ie

window.alert = function('') { return null; }
alert('test!') // works as expected

However, when I try to rewrite window.location = (which is an alias for calling the window.assign () method in a similar way), it does not work

window.location.assign = function('') { return null; }
window.location.assign('#') // redirects :(

I tried setting Window.prototype.location.assign, but I get the exception "Can't change the properties of the wrapped Native."

Any alternatives to NoScript for fine-grained JS control, or is it possible to overwrite specific Native JS methods?

+3
1

alert .

+2

Source: https://habr.com/ru/post/1712739/


All Articles