How to make extension interceipt and modify DOM before rendering or execution

0
down vote
favorite

Is there a way to make FF extension intercept and modify page document after being received and before rendering or execution such as “beforescriptexecute” as it’s no more working.

I need to stop specific harmful inline ‘Java-scripts’ from execution.

i’m currently using indirect way through “webRequest.filterResponseData” to modify request body when being received but it’s only supported in FF57 and doeasnt offer real control

isn’t there a better way like “beforescriptexecute”?

If you want to prevent inline JavaScripts from execution, you could use Content Security Policy on event onHeadersReceived.

Thanks for reply, but I was trying to stop specific scripts not all scripts on page I think StreamFilter is the best approach so far, by the way…few moments ago i was trying to use this code in either content.js or bg.js:

“var eventListenerService = Components.classes[”@mozilla.org/eventlistenerservice;1"]
.getService(Components.interfaces.nsIEventListenerService);"

but it keeps giving me this error 'TypeError: Components.classes is undefined’
any chance you have an idea about this?

Check API compatibility on MDN: https://developer.mozilla.org/Add-ons/WebExtensions/API

Spoiler alert: You can only use the WebExtensions APIs now.

1 Like