Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting my own Firefox extension from a webpage

I am trying to find an easy way to detect if my extension is installed in Firefox 3.6. This should be done from a webpage, probably using javascript.

I've read a lot of blogs that says that I should try loading an image from my extension. Since I own the extension, and I can write the code, that seems like an unnecessary hack.

I've also thought about setting a global variable to the web document, but I havn't been able to achieve this. I thought I would be able to write:

top.window.content.document.hasMyPlugin = true

but this is doesn't seem to work (hasMyPlugin is not defined). I only add this variable when visiting my domain (I have added a WebProgressListener and check the host property), so global namespace pollution shouldn't be a problem.

Any ideas?

UPDATE

The way I try to access the variable is simply if(hasMyPlugin) or if(document.hasMyPlugin)... Perhaps I'm accessing it the wrong way?

like image 751
Max Avatar asked Oct 12 '22 16:10

Max


1 Answers

One simple way is to make your extension react to a user-defined event. Your web page dispatches the event on an appropriate event target (you can use the document if you have nothing better) and then your extension's event listener can verify the web page address and perform an action. At the very minimum your event listener could call preventDefault() on the event; the web page could then call getPreventDefault() to see whether your extension is present.

like image 64
Neil Avatar answered Oct 19 '22 00:10

Neil