Xinus
Xinus

Reputation: 30513

Using NPRuntime plugin in Firefox extension

I have successfully run NPRuntime plugin on webpage by copying it to firefox plugin directory. I want to create a firefox extension using it, so I created small extension that displays a textbox and a button on status bar, button click calls a javascript function which takes value from textbox and passes as a argument to the function in NpRuntime plugin which is embeded in XUL.

But when I try to call the function I get Javascript exception as that variable is null.

try{
var myplugin=document.getElementById("myplugin");
myplugin.test(document.getElementById("txtUri").value);// calling function
}catch(e){
alert(e.message); //throws the error as myplugin is null
}

When I remove function call there is no error so embed tag getting recognized by javascript. I kept a plugin dll in firefox plugins directory. I also tried creating a plugins directory under extension root and keeping my dll in that but it did not succeed .

Please help me get going,

thanks

Upvotes: 0

Views: 1209

Answers (2)

Nick Sawadsky
Nick Sawadsky

Reputation: 143

Calling NPAPI plugins from Firefox extensions is tricky. One option, which seems like a bit of a hack, is to actually inject the plugin into the DOM which represents the browser UI.

A better option is to modify the DOM of pages as they are loaded in to the browser:

Scriptable NPAPI plugin doesn't work with Firefox

Or you can skip the NPAPI plugin altogether, and use js-ctypes:

Using a plugin generated with Firebreath in a Firefox Extension?

Upvotes: 0

Nickolay
Nickolay

Reputation: 32063

"which is embeded in XUL"

How? I bet you use <embed> in the XUL namespace, which doesn't have any special meaning.

You should define the HTML namespace and use the embed tag in the html namespace.

When I remove function call there is no error so embed tag getting recognized by javascript.

This is wrong. If you remove the function call, there's no code left to fail -- getElementById never throws (at least not in such simple cases). This doesn't indicate your XUL code is fine.

I also tried creating a plugins directory under extension root and keeping my dll in that but it did not succeed .

That is definitely supposed to work. Can you put an XPI that demonstrates the problem somewhere?

Upvotes: 1

Related Questions