You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让内容脚本适配youtube.com与youtube-nocookie.com嵌入式YouTube视频?

解决方案:让内容脚本支持youtube-nocookie.com嵌入式视频

问题出在你的content_scripts配置里的matches规则——它只覆盖了youtube.com域名下的页面,而youtube-nocookie.com是独立的官方无cookie域名,所以你的脚本根本不会在这个域名的iframe里运行。

只需要把matches数组扩展一下,加入对youtube-nocookie.com的匹配规则就行,修改后的完整配置如下:

"content_scripts": [
  {
    "matches": [
      "*://*.youtube.com/*",
      "*://*.youtube-nocookie.com/*"
    ],
    "css": [ "app_player.css" ],
    "js": [ "content.js" ],
    "run_at": "document_end",
    "all_frames": true
  }
]

这个修改的作用很直接:

  • *://*.youtube-nocookie.com/*会匹配所有HTTP/HTTPS协议下的youtube-nocookie.com子域名页面(包括嵌入式iframe)
  • 你已经设置的all_frames: true会确保脚本在页面的所有iframe中运行,正好符合嵌入式视频的场景

因为youtube-nocookie的嵌入式页面结构和普通youtube embed完全一致,所以你的现有脚本和CSS不需要做任何额外调整,修改配置后就能正常触发了。

内容的提问来源于stack exchange,提问作者Freelancer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 07:04:03