Search code examples
firefox-addonnpruntime

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


Solution

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