Description
Documentation Feedback
The following code example from the Clipboard documentation for Angular Material 9.0.0 does not work on Firefox:
The problem seems to be that Firefox does not allow Javascript applications to write to the clipboard except synchronously inside a click handler (unless special permissions have been granted):
Therefore, the fact that the attempt
function is called asynchronously using setTimeout
causes the call to fail, with a console warning message saying the copy was "denied because it was not called from inside a short running user-generated event handler".
It's unclear to me why the example code is written with the copy attempts done asynchronously. Running the attempts inline seems to work fine, even for a fairly substantial amount of data:
let clipboardData = 'something to copy';
const pending = this.clipboard.beginCopy(clipboardData);
for (let attempt = 0; attempt < 3; attempt++) {
const result = pending.copy();
if (result) {
console.log('Copied on attempt ' + (attempt+1));
break;
}
}
pending.destroy();
Affected documentation page:
https://material.angular.io/cdk/clipboard/overview