问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/8744726/document-start-for-firefox-addon