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
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:
Hey @feross, would you mind publishing 1.4.2 for me 😄
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.
It is being fixed when moving the window.getSelection().removeAllRanges()
before the var range = new Range()
Version 11.1.1 (12605.2.8)
It'd be useful to add a method which returns whether there is support or not in the current browser.
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.
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.
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
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.
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
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
Just that. Thanks. Very useful and simple module without all the unneeded overload present in other alternatives.
اَلْحَمْدُ لِلّٰهِ رَبِّ الْعٰلَمِيْنَۙ al-ḥamdu lillāhi rabbil-‘ālamīn(a)
Nothing is getting copied to the clipboard in the latest version of chrome. Silent error.
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
在 safri上出现这个错误。。。。
How to migrate from 1.x to 2.0.0?
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.
It is necessary for editor to parse rich text, not just the text content.
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.
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.
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.