feross / clipboard-copy Goto Github PK
View Code? Open in Web Editor NEWLightweight copy to clipboard for the web
License: MIT License
Lightweight copy to clipboard for the web
License: MIT License
It'd be useful to add a method which returns whether there is support or not in the current browser.
I think this got lost under the outdated diff, so reposting here just to be sure:
I was matching the browser API. Even if I reject with an error here, the user can't rely on that, since if the Async Clipboard API is used then it may reject without an error. I thought it was better to be consistent. Will add a comment.
Aha, interesting... I wonder why they would standardize around that 🤔
Do you have a link where I can read about this? I tried searching but to me, it didn't seem like the spec mentioned what the Promise
should be rejected with.
In the chrome examples it seems like they reject with a proper error:
navigator.clipboard.writeText('Text to be copied')
.then(() => {
console.log('Text copied to clipboard');
})
.catch(err => {
// This can happen if the user denies clipboard permissions:
console.error('Could not copy text: ', err);
});
ref: https://developers.google.com/web/updates/2018/03/clipboardapi#copy_writing_text_to_the_clipboard
ping @feross
Nothing is getting copied to the clipboard in the latest version of chrome. Silent error.
Returning promise rejection with 'The request is not allowed' error is failed in Edge browser (v17) with error message in console Function expected
.
For information see following:
اَلْحَمْدُ لِلّٰهِ رَبِّ الْعٰلَمِيْنَۙ al-ḥamdu lillāhi rabbil-‘ālamīn(a)
It is being fixed when moving the window.getSelection().removeAllRanges()
before the var range = new Range()
ERROR in static/js/main.b4d9d765.js from UglifyJs
Unexpected token: name (win) [./node_modules/clipboard-copy/index.js:19,0][static/js/main.b4d9d765.js:295645,6]
1.2.1 works fine
Hello,
Thanks for this nice package.
It seems like the copy doesn't work when the page is loaded into a cross-domain iframe, although the promise returns success. Tested in all major desktop/mobile browsers.
It is necessary for editor to parse rich text, not just the text content.
Hey @feross, would you mind publishing 1.4.2 for me 😄
Let's provide a transpiled to es5 version of this lib. We can do it before publish on npm for example.
Currently this lib is not usable for devices not supporting some of es6+ syntax like async/await, Promise, const etc.
Version 11.1.1 (12605.2.8)
How to migrate from 1.x to 2.0.0?
The README currently says:
Returns success, a boolean which indicates if the copy was successful.
But the code actually returns a promise that resolves if the copy was successful.
在 safri上出现这个错误。。。。
The update to v4 breaks IE11 compatibility because it does not like async
syntax.
Not sure if this lib is still supposed to support IE11, but if not it would be helpful to have a changelog which mentions breaking changes.
I use lookpack domains, e.g. lvh.me
, to develop my web service because it uses subdomains.
As https://developers.google.com/web/updates/2018/03/clipboardapi says, however, navigator.clipboard
only works on https; otherwise, it throws undefined
as permission denied.
It will be nice if the module fallbacks to execCommand("copy")
when witeText()
fails.
Hey,
This package is super useful, it's simple and does it job. Do you plan or can you add paste support? Could be a separate package if you want to keep this low in file size :)
Thanks
So i tried it in dev and it worked great. Worked fine if I was using iOS device. Works fine if it's google chrome and NOT an in-app browser. On Android though, I opened the webpage of my angular 7 app using fb messenger, so it opened using facebook's in-app browser and when I trigger the copy function it caught the below error:
NotAllowedError: Write permission denied.
Not sure if this falls in your domain but thought I should mention it. I'm a beginner programmer so please let me know which details need to be provided.
My typescript code:
getShareLink() {
copy(this.inviteUrl)
.then(data => {
this.successMessage = data;
return this.toastr.success('Link copied to clipboard');
}).catch(err => {
this.failMessage = err;
console.log(err);
});
}
this.failMessage on the front end was NotAllowedError: Write permission denied.
Just that. Thanks. Very useful and simple module without all the unneeded overload present in other alternatives.
I'm getting a TS error about: Cannot invoke an expression whose type lacks a call signature
.
From what I found out, using the following typedef locally works fine:
declare module 'clipboard-copy' {
function clipboardCopy (text: string): Promise<void>
export default clipboardCopy
}
I'm on Typescript 3.2.
clipboard-copy throws a TypeError outside the try-catch, fails to remove the iframe, and fails to copy the text contents on firefox 45.7.0.
A fix exists in PR #5
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.