0

I am developing NPAPI Plugin for Firefox on windows. here is the my java script:

document.addEventListener('load', documentLoad, true);


function loadPlugin(doc) 
{
    var objWebMon = doc.getElementById("my_firefox");

    if(!objWebMon)
    {
        var objWebMonEmbed = doc.createElement('embed');
        objWebMonEmbed.setAttribute('id', 'my_firefox');
        objWebMonEmbed.setAttribute('type', 'application/npplugin');
        objWebMonEmbed.setAttribute('style', 'height: 10px; width:10px; display:block;');
        if(doc.body)
        {
            doc.body.insertBefore(objWebMonEmbed, doc.body.firstChild);

        }
    }
}
function documentLoad(event) {
    try 
    {
    var doc = event.originalTarget; // doc is document that triggered "onload" event
    loadPlugin(doc);
        var myplugin = doc.getElementById('my_firefox');
        if(myplugin)
        {
                myplugin();
            myplugin.myAction();

        }
    } catch(err) 
    {
    }
}

as I am calling myplugin()

bool ScriptablePluginObject::InvokeDefault(const NPVariant *args, uint32_t argCount, NPVariant *result)

gets called sucessfully but on calling function myplugin.myAction()

bool ScriptablePluginObject::Invoke(NPIdentifier name, const NPVariant *args,
                               uint32_t argCount, NPVariant *result)

function doesn't called. I have declared myAction inside ScriptablePluginObject::HasProperty(NPIdentifier name) even HasProperty method is not getting called.

Inside catch block i am getting this error. TypeError: fasso.myAction is not a function.

Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236
Nik
  • 682
  • 1
  • 8
  • 27

1 Answers1

0

Here are a couple of things to try:

  1. Use an object tag instead of an embed -- I've had more consistent success with object tags, despite the wide popularity of using embed
  2. Never ever ever set the type of an object or embed tag before you add it to the DOM -- doing so causes it to instantiate the plugin and then puts it in a kinda weird state when it gets moved. I don't think this is causing your issue this time, but it's worth trying.
  3. You may need a slight delay between inserting hte plugin into the DOM and using it. Try adding a setTimeout with a delay of 50ms and accessing the plugin in the callback function.

Honestly, #3 is the one I think most likely will make a difference, but I present the other two as they have bitten me on weird things in the past. Good luck!

taxilian
  • 14,229
  • 4
  • 34
  • 73