JSFiddle - React, Tailwind, and code Playground

HTML

<p>JS-driven copy is: <span></span></p>

JavaScript

var rng = document.createRange();
rng.selectNodeContents(document.getElementsByTagName('p')[0]);
window.getSelection().addRange(rng);
var str = '';
try{
    str = document.queryCommandSupported('copy') ? 'supported' : 'unsupported';
    str += document.queryCommandEnabled('copy') ? ' & enabled' : ', not enabled';
}catch(e){
    str += ' (exception '+e + ')';
}
document.getElementsByTagName('span')[0].textContent = str;
window.getSelection().removeAllRanges();