execCommand('copy') intermittently fails on programmatic selection without focus
Reported by
d...@moqups.com,
Aug 12 2017
|
|||||
Issue descriptionUserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36 Steps to reproduce the problem: This is a simplified test case based on the article: https://developers.google.com/web/updates/2015/04/cut-and-copy-commands and refers to a previous comment I made on #722925: https://bugs.chromium.org/p/chromium/issues/detail?id=722925#c20 1. open the attached test case 2. select "Lorem" and press Cmd + C to copy it to the clipboard, confirm by pasting into textarea below 3. Press the "copy" button to try to copy the email address to the clipboard 4. Pasting into the textarea What is the expected behavior? Pasting should reveal "matt@example.co.uk" What went wrong? Pasting reveals "Lorem" in (most) cases. Did this work before? Yes Chrome 59 Does this work in other browsers? Yes Chrome version: 60.0.3112.90 Channel: stable OS Version: OS X 10.12.6 Flash Version: Note that pressing "Copy" twice will indeed copy the email address to the clipboard.
,
Aug 14 2017
Able to reproduce the issue on Windows-7,Windows-10,Mac-10.12.4 and Linux Ubuntu-14.04 using chrome stable version # 60.0.3112.90 and canary 62.0.3185.0 with the steps mentioned in comment#0 As per comment #1 Good Build Revision: 464694 Bad Build Revision : 464699 Using the per-revision bisect providing Changelog: You are probably looking for a change made after 464697 (known good), but no later than 464698 (first known bad). CHANGE-LOG URL: --------------- https://chromium.googlesource.com/chromium/src/+log/188c1056bbfb9c98eca691c12f5641d4204f6066..0f65d25a4097959d977dbb1077717323438240a6 Suspecting https://codereview.chromium.org/2616623002 from changelog @hugoh: Could you please take a look into this issue and reassign if this issue is not related to your change. Thanks..!!
,
Aug 14 2017
,
Aug 14 2017
Assigning over to xiaochengh@ because he knows more about execCommand('copy').
,
Aug 14 2017
The API is working as intended. The test case is not, because the button's event handler doesn't always select the link text:
// Select the email link anchor text
var emailLink = document.querySelector('.js-emaillink');
var range = document.createRange();
range.selectNode(emailLink);
window.getSelection().addRange(range);
Selection.addRange() doesn't do anything if the document already has a selection (*). To correct the test case, call Selection.removeAllRanges() before calling Selection.addRange().
(*) Spec of Selection.addRange(). http://w3c.github.io/selection-api/#dom-selection-addrange. "... If rangeCount is not 0, abort these steps. ..."
,
Aug 14 2017
Thank you for the clarification, and for reviewing my submission. You are correct, I had missed this aspect.
,
Aug 15 2017
If you wanna upstream your test, I think you can send it to https://github.com/w3c/web-platform-tests/tree/master/selection . We always need better test coverage :) |
|||||
►
Sign in to add a comment |
|||||
Comment 1 by woxxom@gmail.com
, Aug 12 2017