Skip to content
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

addRange fails in Chrome in some context #57

Open
FlavienBusseuil opened this issue Sep 29, 2017 · 3 comments
Open

addRange fails in Chrome in some context #57

FlavienBusseuil opened this issue Sep 29, 2017 · 3 comments

Comments

@FlavienBusseuil
Copy link

FlavienBusseuil commented Sep 29, 2017

I have a very specific issue in Chrome.

The first attempt to copy the content of an input content fails because somehow when document.body.appendChild(mark) is called in copy() the selection is not null.
Instead the type in selection.type is set to Caret and so the rangeCountis equal to 1. Which, I suppose, made addRange fails due, I suppose again, to this error in my console:

[Deprecation] The behavior that Selection.addRange() merges existing Range and the specified Range was removed. See https://www.chromestatus.com/features/6680566019653632 for more details.

If I click somewhere in my input before the copy, it works. Don't know what's the mess with the caret?!

I'm on a mac and it works in safari. Also I'm using copy-to-clipboard through react-copy-to-clipboard.

Thanks

EDIT: As a work around I put a autofocus on the input field and it works.

@sudodoki
Copy link
Owner

Hey, sorry to hear that. Can you, please, link to a reprocase in smth like jsbin/etc and provide 1) steps to reproduce, 2) chrome & OS version?

@FlavienBusseuil
Copy link
Author

I'm not sure how to reproduce this... I'm in a pretty big project/environment. I will try to find out a simple reprocase I can share when possible.

I use Chrome 61.0.3163.91 and Mac Sierra 10.12.6

@yataras
Copy link

yataras commented Oct 8, 2017

I have the similar problem. It occurs very rarely. In most cases - after login in and using the copy() function for the first time. Chrome gives me a message: "[Deprecation] The behavior that Selection.addRange() merges existing Range...". After that I can successfully copy text to clipboard.
I've fixed it by adding before the copy('Text') next lines:
const select = window.getSelection();
select.removeAllRanges();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants