-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uncaught TypeError: Illegal constructor Error #1181
Comments
Is Clipboard.js included on the page? Do you have a public, reproducible example? |
@mAAdhaTTah I don't have clipboard.js installed on that website. Also I have prism running in the backend of a custom cms so I can't show you the URL. |
You need Clipboard.js installed. That's what handles the clipboard interactions. The "invalid constructor" is the attempt to instantiate the Clipboard.js object failing. |
This was also a problem with webpack. The problem was the same: use clipboard/lib/clipboard.js instead of the dist. This seems to be an issue with how they transpile. |
Any chance your browser is Chrome v61? Chrome v61 added a window.Clipboard which is probably causing a namespace collision with copyToClipboard plugin. I only got the error on Chrome v61, tested on Chrome v60 and v61. |
Did it really? We check Poking at it in the console, it doesn't appear to... do anything. I can't Hoping Chrome will provide some docs on this feature so maybe we can figure out how to detect it properly or Clipboard.js changes the global name. I don't have a solution off the top though. |
@ayumihamsaki Anything after 61 will have this problem, as that's when the global |
I was having the same problem with Prism installed manually in a Wordpress theme. Adding clipboard.js explicitly solved the issue in Chrome 61 and Canary (63.0.3213.0). @mAAdhaTTah Chromestatus has an entry for Asynchronous Clipboard API. It also has a couple links to demos and docs. The links point to an explainer and the proposal at wicg Hope this helps |
@caraya Thanks, that might be it, but Chrome 61 (or 63) doesn't have a Update: Yes, the Just so everyone knows, this can be resolved by including Clipboard.js yourself, either in a script tag or bundled into your JS. It's specifically the plugin's behavior to fallback to a CDN version if it doesn't find Clipboard.js that is failing. |
In my scenario
i just inverting the position of the copy-to-clipboard plugin to be the first one to be loaded, and problem solved!.
However loading the plugin before the main component seems a bit strange... NS |
I added:
It's essentially the same thing as adding the clipboard script to |
@timhemendinger I tried that but didn't get it to work - do you have a diff ? |
If you're using PrismJS in a custom wordpress plugin, you can enqueue "clipboard.min.js" before you enqueue "prismJS" like so...
|
So the |
@Golmote Would it be a terrible hack to do something like this instead: /(native code)/.test(window.Clipboard.toString()) |
Chrome now ships with a window.Clipboard built in, which breaks this check. This ensures we're not grabbing the built-in Clipboard and definitely have the correct package version. Fixes PrismJS#1181.
Chrome now ships with a window.Clipboard built in, which breaks this check. This ensures we're not grabbing the built-in Clipboard and definitely have the correct package version. Fixes PrismJS#1181.
This version of the fix is here: #1206. |
Chrome now ships with a window.Clipboard built in, which breaks this check. This ensures we're not grabbing the built-in Clipboard and definitely have the correct package version. Fixes #1181.
Hi,
I am getting this error:
It seems to be showing when I add the "Copy to Clipboard Button" package.
My browser I am getting the error is Google Chrome Version 62.0.3200.0 (Official Build)
Here is a screenshot of the error in dev tools:
For now I am just going to live with out adding this plugin. I thought I'd let you know anyway.
p.s. Normal setup works fine no problem. It only appears with this plugin addon.
The text was updated successfully, but these errors were encountered: