In what context does Javascript for XUL run?

Is it possible for the javascript you write for the XUL component to interact with the javascript defined in the web page?

For example, if a particular web page has a dooSomethingNeat () function, can I specify a button defined in the XUL overlay, execute that function, or live in a different namespace?

Put another way: if I want to improve the functionality of a website through my own code, does it make sense to write a Firefox extension or use something like greasemonkey?

+2


source to share


2 answers


See my answer to another question here .

  • Web page code lives in a "namespace" separate from the scopes in which browser code runs.
  • This does not mean that you cannot access it from the extension.
  • On the other hand, running a function on a content page is not easy to do safely at the moment.
  • Greasemonkey scripts (and ubiquitous scripts that can also interact with web pages) are somewhat easier to develop than extensions, and Greasemonkey already implements the necessary precautions so that you can safely interact with web pages.
  • If you want others to use your script, packaging it as a separate extension lowers the barrier to entry (otherwise, existing GM users might prefer simpler GM scripts for a separate extension).


So, if you can implement what you need to do with a GM script or an ubiquitous script, I'd say go with it. At the very least, you can start with it and then convert to an extension when you find something you can't do with GM.

If you need features not supported by Greasemonkey, or if you just want to try building an extension, this is also a viable option.

+2


source


There is a Greasemonkey-to-firefox-extension compiler , but it is not updated with the latest GM changes.

It does, however, have a basic GM framework for page interaction and security, which is wrapped up as a standalone extension ready for you to modify and extend.



Wether to use a stand-alone extension or GM-script depends on who installs it. Will the user base be ready to install GreaseMonkey, THEN script? Or is one extension enough to install the barrier?

The GM license permits repackaging with pre-scripted scripts I suppose, but I can't find back quotes for this at the moment.

+1


source







All Articles