4

Chrome provides a copy(myCopyObj) to copy an object. Do we have anything similar in terms of pasting an object or getting the contents from the clipboard?

Vikramjit Roy
  • 396
  • 3
  • 7

2 Answers2

1

Press enter after copy(myCopyObj) then try to Paste(ctrl+V). This will solve your purpose.

  • I think the question is about accessing the clipboard content directly as a programmatic expression, like how `copy` takes an expression and sets the clipboard. You can use `ctrl+v` to paste the value into a string literal. But this is inconvenient if the clipboard is a string that contains newlines, which will need to be escaped from the string literal, or if it is an image or something else. – Ben J Sep 01 '20 at 11:38
1

"Getting the contents from clipboard"

Execute the following on devtools side and within 3 seconds focus on the window (by clicking somewhere, or just hitting <tab>).

setTimeout(async()=>console.log(await window.navigator.clipboard.readText()), 3000)

This will just print the clipboard content. You can replace console.log with code that actually uses the clipboard content.

Jannis Ioannou
  • 572
  • 1
  • 5
  • 9