开发者

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.mes开发者_开发技巧sage); //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


"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?


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜