I am creating a web extension to help detecting postMessage activity in websites. Therefore, I want to detect it when a page attaches a message
event listener, for example by calling this code:
window.addEventListener("message", ...)
Apparently it is not possible to get a list of event listeners. My next idea was to override addEventListener
, so I can detect calls to it:
window.addEventListener = function(type) {
if (type == "message") {
// do something
}
}
I have trouble injecting this code into the page:
How can I override window.addEventListener globally from my extension? Or alternatively, is there another way to detect an event listener on message
events?
Introduction. It is true that JavaScript supports overriding, not overloading. When you define multiple functions that have the same name, the last one defined will override all the previously defined ones and every time when you invoke a function, the last defined one will get executed.
Choose a file like a Javascript or CSS files, right click it and choose "Save for overrides." The file you choose will now appear in the Overrides tab. Now, any changes you make to the file will persist throughout page reloads and navigating pages in the website as long as the devtools is running.
Overriding a method replaces the code of the method in the superclass with that of the subclass.
To override a function, you need to run JavaScript before the page loads. You need to do the following:
run_at
to document_start
.script.textContent = actualCode
and not script.src = url
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With