Is it possible to inject a javascript code that OVERRIDES the one existing in a DOM? (e.g default alert function)

前端 未结 1 730
傲寒
傲寒 2020-11-30 14:06

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 b

1条回答
  •  旧时难觅i
    2020-11-30 14:45

    Functions don't exist as part of the DOM; instead, they exist within an execution environment that includes the DOM. Content scripts (including scripts run with executeScript) and actual web pages share the same DOM, but have separate execution environments. So calling window.alert = function() {} only rewrites window.alert within your content script's execution environment, not in the actual page's one.

    The typical way to reach the execution environment of the actual page is to inject a

提交回复
热议问题