سؤال

i have created a chrome extension. now, i want to change it to a NPAPI plugin. i have used npsimple sample code(from chrome) to build plugin. now the issue is:

i have following java script chrome extension file code:

//test.js

chrome.browserAction.onClicked.addListener(function(tab) 
{   
    //this file calls content script file  
});

this file is called when ever i click on extension icon. now we don't want to call this file by clicking on extension(want to call it when plugin is loaded). so we can have some other event also. now i have to call test.js file from NPAPI plugin.i have no idea how can i do that. can we fire some fake event from NPAPI plugin inside NPN_INVOKE and register a listener in js file and execute js file. or is there any way to inject this file in NPAPI code.

is there any other better way..

please help.. thanks in advance...

هل كانت مفيدة؟

المحلول

There are two options. You can use NPN_Evaluate or you can get a reference to the window object with NPN_GetValue:

NPObject* window;
NPError err = NPN_GetValue(pNPP, NPNVWindowNPObject, &window);

Once you have the window NPObject then you can invoke global javascript functions with NPN_Invoke and get/set properties with NPN_GetProperty and NPN_SetProperty.

You might consider using FireBreath, which hugely simplifies all of this.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top