Frage

I am trying to access NPAPI plugin from content/inject script of Chrome/Safari extensions.

The code to embed the plugin object and access methods.

var newElement = document.createElement("embed");  
newElement.id = "myPluginID";  
newElement.type = "application/x-mychrome-plugin";
var newAttr = document.createAttribute("hidden");
newAttr.nodeValue = "true"
newElement.setAttributeNode(newAttr);
newElement.style.zIndex = "-1";
newElement.style.position = "absolute"; 
newElement.style.top = "0px";
document.documentElement.appendChild(newElement);
plugin = document.getElementById("myPluginID"); //this shows as HTML element when evaluated in JavaScript console.


   plugin.myPluginMethod() // this shows as undefined instead of native code(When evaluated in JavaScript console),for pages where NPP_New is not called.

This works for most of the webpages,but for few pages(eg:www.stumbleupon.com),NPP_New is not called(debugging using Xcode 4) and scriptable object is not created and all the plugin methods are undefined.

Any inputs.

War es hilfreich?

Lösung

Why are you putting your embed as a child of document.documentElement (i.e., <html>) instead of in the body? I wouldn't expect a plugin that's not going to be displayed to be instantiated.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top