Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"document_start" for Firefox addon?

I come from Chrome extensions, so I'm used to defining when a file should be injected by setting run_at, e.g., to document_start for injection before DOM construction. Is there an equivalent for Firefox addons?

like image 387
Kar Avatar asked Apr 09 '26 21:04

Kar


1 Answers

Yes, the equivalent would be the content-document-global-created notification. An extension can add an observer for that notification and then do something with the window - like injecting a content script. See How to override JS function from a firefox extension? for one example of using this notification.

If you use the Add-on SDK it will do this job for you. The page-mod package supports a contentScriptWhen parameter - you can use "start" as its value and the content script will be injected before any page scripts get a chance to run.