Answer the question
In order to leave comments, you need to log in
How to disable JavaScript injection from the site through userscripts?
How to disable JavaScript injection from the site through userscripts?
I have a site Vkontakte, there is a button - send a message.
I need my code to work when I click on this button, not the website code. If you simply cancel the request to the server for this javascript, then all the functionality of the site will not work. I need to somehow change the response body, or rather, after the request is executed, not much change this javascript. chrome.webRequest can't. Then I decided to simply remove the loading of this script at the beginning of the page load, but this didn’t work out for me either, the browser connects this JavaScript faster than my extension.
Then my eyes fell on userscripts. And maybe somehow through it, you can remove the script loading from html in order to insert my script. Or is it still possible to somehow change the response body so that I can edit the javascript that the server sends?
In short, I've been steaming with all this for about 5 days. I want to solve this problem. And for this, only one server-side JavaScript code bothers me.
Answer the question
In order to leave comments, you need to log in
On the element where the event handler hangs , you need to hang:
.addEventListener('click', event => {
event.stopPropagation()
...
}, true);
You can easily rewrite VKontakte scripts to your own through the content script / UserScript, just declare your function and it will stupidly replace the function from VKontakte.
An example of declaring the test() function via the content script / UserScript:
var script = document.createElement('script');
script.innerHTML = `function test() {
// Ваш код
}`;
document.head.appendChild(script);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question