Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

devtools console: copy is not a function while on youtube

I know that I can use copy() function on the console to add content to the clipboard.

When I am on any other page copy('test') works.

When I am on youtube I get:

Uncaught TypeError: copy is not a function

How can I fix this. E.g. Is there a way to prevent a site from overriding specific functions using devtools?

Strangely on firefox copy() works on youtube, so could this be a chrome bug?

like image 458
Jannis Ioannou Avatar asked Jun 05 '20 10:06

Jannis Ioannou


1 Answers

The issue is that there is an element on that page with id="copy". If you type copy in the console, you should get a element printed out like this:

$ copy
<g id="copy"></g>

So, you'll have to remove that element before using the copy function:

document.querySelector('#copy').remove();

Running it in console again should show it's a function:

$ copy
ƒ copy() { [native code] }

Then use copy() as normal, e.g. copy(myVariable)

like image 86
dǝɥɔS ʇoıןןƎ Avatar answered Nov 17 '22 18:11

dǝɥɔS ʇoıןןƎ