0

I am getting a JavaScript error: Error calling method on NPObject when calling a method in my NPAPI plugin in Chrome & Firefox on XP. Running the same code on Windows 7 with the same browsers was successful.

I have built a Scriptable plugin using the NPAPI, so far I can debug into the Invoke method of my scriptable object. But I don't believe I have any control after it's finished.
Does anyone have any ideas? Is this an issue only in Windows XP?

bool MY_ScriptableObject::Invoke(NPObject*        npobj,   
                                 NPIdentifier     name,    
                                 const NPVariant* args,    
                                 uint32_t         argCount,
                                 NPVariant*       result)  
{ 
bool                    rc   = true;
char*                   wptr = NULL;

    rc = false;
    wptr = NULL;

    if  (name == NPN_GetStringIdentifier("getVersion"))
        {
        wptr = (NPUTF8*)NPN_MemAlloc(strlen("version:1.0.1") + 1); //Should be freed by browser
        if  (wptr != NULL)                                                      
            {
            rc = true;
            memset(wptr,
                   0x00,
                   strlen("version:1.0.1")+1);
            memcpy(wptr,
                   "version:1.0.1",
                   strlen("version:1.0.1"));
            STRINGZ_TO_NPVARIANT(wptr,
                                 *result);
            }
        }
    return (rc);
}

Here is the HTML function that I am executing:

function Version()
{
var plugin = document.getElementById("plugin");
if (plugin == undefined)
    {
    alert("plugin failed");
    return;
    }
var text = plugin.getVersion();  //Error happens at this line
alert(text);
}
Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236
hapyfishrmn
  • 177
  • 2
  • 21
  • Format your code to a considerably understable state, pretty please? – Eitan T Jun 27 '12 at 17:09
  • Im not sure what is wrong with how my code is formatted? – hapyfishrmn Jun 27 '12 at 19:16
  • 1
    Just FYI hapyfishrmn, you shouldn't rollback helpful edits. @EitanT showed you what was wrong with your code formatting and fixed it so others could more easily read and understand your code. Why you undid that, I don't know. – jamesmortensen Sep 21 '12 at 16:15
  • @jmort253 Everyone has their own preference when it comes to formatting if there is one to follow here I will gladly do so (I looked but didn't find one), but it seems like he was going out of his way to make changes that fits his understanding but not provide any help to the cause. I am fine with someone changing my question to be helpful and make it more understanding for those to come. – hapyfishrmn Sep 28 '12 at 16:39
  • If it helps @hapyfishrmn, I thought he made it easier to read. Keep in mind that it will ***always*** be easier to read your own code, no matter how it's formatted. As the single author of our code, we have a bit of a bias that doesn't extend to the N possible readers of our code. Also, what Eitan did is more "standards compliant", which means more people are likely to be able to assimilate faster than by having something here that isn't what's expected. Hope this helps! :) – jamesmortensen Sep 28 '12 at 16:45

1 Answers1

1

The (sarcasm)awesome(/sarcasm) thing about NPAPI in current versions of the browsers is that if anything goes wrong with the call you automatically get that error message, even if the plugin has otherwise tried to set an exception with NPN_SetException.

My first guess would be that you compiled your code targeting a later version of windows than windows XP; I'm not sure if that would produce this issue or not. I have never seen the issue you're describing, and I've got plugins running on xp, vista, and 7 with no trouble. You might also try playing with a FireBreath plugin and see if the issue occurs there or not.

I would recommend that you attach with a debugger and set some breakpoints. Start in NPN_GetValue and make sure that it's instantiating your NPObject, then set breakpoints in your NPObject's HasMethod and Invoke methods and see what is hit. Likely something in there will show you what is actually happening, or at least tell you what code is or isn't getting hit.

taxilian
  • 14,229
  • 4
  • 34
  • 73