Can JavaScript's navigator clipboard be used in Browser Source Interact?

Fatorin

New Member
I've developed a tool for streamers to manage their listeners during participatory streams.

The tool includes a function that allows streamers to copy text (such as username or game ID) to the clipboard by simply touching a button or text.

However, this function doesn't work in Browser Source Interact.

Can copy text by highlighting it, but it's not very efficient that way.

Are there any methods to solve this issue?
 

Fatorin

New Member
"Finally, I found a simple way to solve this issue by using this JavaScript library: Clipboard.js.

However, I noticed that it uses a deprecated function, document.execCommand(), to implement the copy/paste function. We'll need to wait for older browsers to support the navigator.clipboard function."
 

AlphaSpirit

New Member
Hi brother,

I am old in this thing. It was a time when the only thing you could use was the deprecated (for ages) - document.execCommand("copy"); - without any alternative there.

I am still using the deprecated function in my apps. Even the Visual Studio Code was highlighting this as deprecated for decades. I don't think they are going to remove it any soon because the new functions are really new. Use the deprecated one with confidence.

My advice is not use the library you mentioned about. Use the document.execCommand("copy") directly on your form or hidden element. You need to make a selection for this to work.

JavaScript:
select_all(event) {
  let el = event.target;
  if (!el.classList.contains("effect_instances_save")) return;
  let range = document.createRange();
  range.selectNode(el);
  window.getSelection().removeAllRanges();
  window.getSelection().addRange(range);
  document.execCommand("copy");
  // window.getSelection().removeAllRanges();
  el.parentNode.querySelector(".effect_instances_save_message").innerHTML = "OK! Contents have been copied to clipboard.<br> Now Paste in a text editor and <br> save file with a .json extension";
}

Keep in touch to collaborate in our projects.
 
Top