Ok, so what I want is to override a method that already exists inside a tab, what I'm going to use is the default alert function.
Override it inside the JS function would be very easy. just add
window.alert = function(){
//Do Something
}
but the problem is that when I try to use chrome.tabs.executeScript("window.alert = function() { };");
it doesn't work. I tried to do this manually by using the Console from Chrome in the tab that I wanted to override the function, I typed that override function in the log and pressed enter, and done, the alert function was overridden, but I can't do this via Chrome Extension.
When you add executeScript, it seems like it creates a Javascript apart from the one inside the tab DOM, because I can create functions with the name of a function that already exists inside the tab DOM.
Is there a way to make executeScript to write the script inside of the tab DOM, so it can actually override any function that was written by the .js file the page generated?
Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…