clipboard.js: Name conflict on chrome 61+

Chrome version 61 has added a Clipboard object, i still can’t find any documentation on this new object: on the console:

window.Clipboard ƒ Clipboard() { [native code] }

Now when this plugin is loaded on a page it overwrittes de original definition of Chrome I don’t know if it has any impact yet, may be this plugin could take a new name to avoid conflicts?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 20
  • Comments: 38 (1 by maintainers)

Commits related to this issue

Most upvoted comments

For backward compatibility, you could make both variables available (Clipboard and ClipboardJS for example). Pushing the idea forward, you could even add a method to restore the original Clipboard value after initialisation. Like jQuery.noConflict() does, restoring the initial value of $ and still being accessible with jQuery.

EDIT: Underscore.js provides the same utility: http://underscorejs.org/#noConflict. So does Lodash: https://lodash.com/docs/#noConflict.

I’m having the same issue.

Uncaught TypeError: Illegal constructor

When calling new Clipboard

Only happens on Chrome 61

@jimcaven You’re probably still doing new Clipboard in ur code; you need new ClipboardJS with the new version.

In the meanwhile, you can install a modified, working copy from my fork

[ClipboardJS v2.0.1 CDN] @ https://cdn.rawgit.com/rivy/js.ClipboardJS/021e74439d7d64da9e44bbfb488850ed7a4dadf4/dist/clipboard.min.js

It’s labeled as “v2.0.1” because it’s a breaking change, renaming all instances of “Clipboard” and “ClipboardAction” to “ClipboardJS” and “ClipboardJSAction”, respectively. Change your code accordingly and it should be working correctly again, even in the most recent browser versions.

Hmm. So @zenorocha should consider to change it to ClipboardJS or simular. @zenorocha do you want a PR for this?

Shouldn’t this result in a 2.0 release? You can’t overwrite window.Clipboard if Chrome provides a native implementation because the interfaces are not compatible. You also can’t just do nothing since doing so breaks anyone’s code who depends on clipboard.js. Both these approaches lead to breakage. I think moving forward, yes, the name of the constructor absolutely should be changed to something else (e.g. ClipboardJS).

@mAAdhaTTah I think it’s part of the Asynchronous Clipboard API. navigator.clipboard is supposed to return a Clipboard object (though it doesn’t work currently AFAICT. I think Chrome has started implementing it.

I am using the latest CDN (https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.min.js) and still seeing the Illegal constructor error…

Running latest Chrome: Version 64.0.3282.186 (Official Build) (64-bit)

Could old versions be cached or something?

Hey everybody,

Sorry for taking so long to fix this. A 2.0.0 release has been published with the proper fix.

https://github.com/zenorocha/clipboard.js/releases/tag/v2.0.0

Unfortunately this is a breaking change that is not backwards compatible.