Search code examples
javascriptfirefox-addongreasemonkeyxpcom

How to call a user javascript from a firefox plugin


I am very new to writing plugins for firefox. I am writing a plugin to intercept a URL protocol (I got it here: http://www.nexgenmedia.net/docs/protocol/) inside the plugin and then call some user loaded Jscript functions to pass data.

My question is, How can i call a user script or a greasemonkey script from within a firefox plugin when the plugin is running.


Solution

  • This is generally a very bad idea to run arbitrary code from an extension. The extension code is executed in privileged mode with access to XPCOM (and thus the whole system). If you really DO want to execute external JS, the best way is Components.utils.Sandbox I suppose. Other options are nsISubscriptLoader or Components.utils.import. Also, afaik such extensions won't pass security check at Mozilla Addons and won't be accepted there as a result.