最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - devtools console: copy is not a function while on youtube - Stack Overflow

programmeradmin4浏览0评论

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?

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?

Share Improve this question edited Jun 5, 2020 at 10:25 Jannis Ioannou asked Jun 5, 2020 at 10:12 Jannis IoannouJannis Ioannou 2,2211 gold badge19 silver badges20 bronze badges 4
  • 3 Run copy in console and you'll see it's a DOM element with id copy. Once you remove this element you can use the built-in API. – woxxom Commented Jun 5, 2020 at 10:39
  • 1 @wOxxOm Thank you for the feedback. indeed document.querySelector('#copy').remove() works. I wonder why does this happen? Are ids supposed to be accessible as variables? I try to access a differrent id by its name but I cannot. And why this does not work on firefox? – Jannis Ioannou Commented Jun 5, 2020 at 11:15
  • 2 1) see Do DOM tree elements with ids bee global variables?, 2) dunno, but google is known to serve different sites to non-chrome browsers. – woxxom Commented Jun 5, 2020 at 11:25
  • Is there anyway to reinstate copy? – Jikku Jose Commented Sep 27, 2020 at 6:42
Add a ment  | 

1 Answer 1

Reset to default 16

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)

发布评论

评论列表(0)

  1. 暂无评论