ZeroClipboard JavaScript library throws Uncaught Error: Error calling method on NPObject

StackOverflow https://stackoverflow.com/questions/16708453

  •  30-05-2022
  •  | 
  •  

Question

I am trying to copy content to clipboard using https://github.com/zeroclipboard/ZeroClipboard. It seems a good library, but I am getting the error 'Error calling method on NPObject.' when the copy button (a flash) is hovered.

Seems like a flash security problem, but I am able to load the flash content.

Any ideas?

Was it helpful?

Solution 2

I got it work. It was a same origin security model breech. My web apps subdomain was 'WWW' but the flash content was served from 'CDN'. Just rendered both the contents from same subdomain.

Find more @ https://developer.mozilla.org/en-US/docs/Gecko_Plugin_API_Reference/Scripting_plugins?redirectlocale=en-US&redirectslug=Gecko_Plugin_API_Reference%3AScripting_plugins#NPObject

Thanks.

OTHER TIPS

In versions after 1.1.7, if you hosted "ZeroClipboard.swf" on a different domain than the hosting page, you need to set "allowScriptAccess" to "always" other than "sameDomain", also "trustedDomains" should contain current page domain.

ZeroClipboard.setDefaults( { moviePath:'http://YOURSERVER/path/ZeroClipboard.swf',allowScriptAccess: "always",trustedDomains: location.hostname } );

Please add "trustedDomains : [*]"

Tha't how I fixed my problem.

var clip = new ZeroClipboard(document.getElementById("copy-button"), {
    trustedDomains: [ "*" ],
    moviePath: "http://assets.dev.alipay.net/gallery/zeroclipboard/1.2.2/ZeroClipboard.swf"
});

For more details: https://github.com/zeroclipboard/zeroclipboard/issues/103

I just updated from 1.0.7 to 1.1.7 yesterday and I'm experiencing the same issue... I'm wondering if they broke something with a commit they did yesterday because this is the only post I've seen about the issue.

~Seth

In case this helps anyone else, I managed to make this error go away for my setup (developing locally at http://localhost:3000 and loading the Flash file from cdnjs. CoffeeScript:

if ZeroClipboard?
    ZeroClipboard.setDefaults
        moviePath: "//cdnjs.cloudflare.com/ajax/libs/zeroclipboard/1.1.7/ZeroClipboard.swf"
        trustedOrigins: [window.location.protocol + "//" + window.location.host]
        trustedDomains: window.location.hostname
        allowScriptAccess: "always"

Note that trustedDomains is the key here. Even though it's supposedly deprecated in 1.1.7, removing it (for me at least) causes the dreaded Error calling method on NPObject error to return.

Or else your domain is not ssl secured i.e your protocol is http instead of https so you should alter your swf link from

https://davidwalsh.name/demo/ZeroClipboard.swf

To

http://davidwalsh.name/demo/ZeroClipboard.swf

For further details please check Cross-Protocol Limitations topic in the following documentation

http://www.kellyjandrews.com/zc/guides/limitations/protocol/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top