Open Bug 1231311 Opened 9 years ago Updated 2 years ago

document.execCommand('copy') causes 'too much recursion' in ver42

Categories

(Core :: DOM: UI Events & Focus Handling, defect)

42 Branch
defect

Tracking

()

People

(Reporter: mikagenic, Unassigned)

Details

User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.73 Safari/537.36

Steps to reproduce:

see http://jsfiddle.net/Lxjdfe7e/

select the line in the teaxtarea and press control+C

The relevant code is:

function copyHtmlToClipboard(html) {
  var div = document.createElement("div");
  div.style.position = 'absolute';
  div.style.top = '-1000px';
  div.style.left = '-1000px';
  div.innerHTML = html;
  document.body.appendChild(div);
  
  window.getSelection().removeAllRanges();  
  var range = document.createRange();  
  range.selectNode(div.firstChild); 
  window.getSelection().addRange(range);  

  var ok=false;
  try {
    ok = document.execCommand('copy');
  } catch (err) {
  }
  if (!ok) console.log('execCommand failed!');

  window.getSelection().removeAllRanges();  
  document.body.removeChild(div);
}




Actual results:

Firefox 42 does not copy the text to the clipboard. In the firebug console I see 'too much recursion'


Expected results:

In chrome and IE11 this will copy xx in bold to the clipboard. This can be verified by for example pasting into a gmail new email.
Status: UNCONFIRMED → NEW
Component: Untriaged → Event Handling
Ever confirmed: true
Product: Firefox → Core
Component: Event Handling → User events and focus handling
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.