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

如何将contextMenus仅限制在http/https/about:newtab/about:blank页面?

配置上下文菜单仅在指定页面显示

如果不设置documentUrlPatterns,你的扩展上下文菜单虽然能在about:newtab显示,但也会意外出现在moz-extension:、其他about:这类非目标页面里。要让菜单只在你需要的页面显示,直接用匹配模式配置documentUrlPatterns字段就行,指定以下规则:

documentUrlPatterns: [
  'http://*/*',
  'https://*/*',
  'about:newtab',
  'about:blank'
]

每个规则的作用:

  • http://*/* 和 https://*/*:覆盖所有HTTP、HTTPS协议的网页
  • about:newtab:仅匹配浏览器新标签页
  • about:blank:仅匹配空白页面

把这段配置加到你的chrome.contextMenus.create()调用里,就能精准控制菜单的显示范围,避免在非目标页面出现。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 16:52:09