Chrome扩展content_scripts的matches数组设置问题及审核咨询
Chrome扩展商店审核被拒:content_scripts的matches配置问题
我正在开发一款Chrome扩展,希望它仅在特定站点运行,因此在manifest.json中配置了content_scripts字段,具体配置如下:
"content_scripts": [ { "matches": ["https://*.amazon.*/*", "https://*.ebay.*/*","https://*.bestbuy.*/*/"], "js": ["src/ethical_extension.js"], "run_at": "document_end" } ]
提交至Chrome商店时被拒绝,提示:
Violation reference ID: Yellow Magnesium
Violation: Not providing promised functionality
"giving Invalid value for 'content_scripts[0].matches[0]'"
将matches设置为<all_urls>时,提交可正常通过审核并发布。我的问题是:matches数组是否存在必填项以通过自动化测试?或者是否需要在content script文件内直接实现站点过滤?
问题原因与解决办法
你遇到的审核报错,核心是matches里的URL匹配规则不符合Chrome扩展的语法规范。看你配置里的https://*.bestbuy.*/*/,末尾多了个斜杠——Chrome的匹配模式中,/*已经能匹配所有子路径及文件,额外加斜杠属于无效语法,这大概率是触发错误的直接原因。
1. 修正matches配置
先把错误的规则改对,将https://*.bestbuy.*/*/改成https://*.bestbuy.*/*,修正后的完整配置:
"content_scripts": [ { "matches": ["https://*.amazon.*/*", "https://*.ebay.*/*","https://*.bestbuy.*/*"], "js": ["src/ethical_extension.js"], "run_at": "document_end" } ]
同时确认所有规则符合Chrome的匹配规范:
- 通配符
*只能用在域名前缀(如*.example.com)或路径的任意位置(如/path/*) - 不要在规则末尾加多余的斜杠或无效字符
2. 关于你的问题解答
- matches数组没有所谓的“必填项”,但必须严格遵循Chrome的URL匹配语法,否则会触发自动化审核的校验错误。
- 如果担心匹配规则的兼容性,或者审核仍出现误判,也可以用
<all_urls>配合content script内的站点过滤:在ethical_extension.js开头加入判断逻辑,不符合目标站点就直接终止执行,示例代码:
// 先判断当前站点是否在允许列表内 const allowedPatterns = [/amazon\..+/, /ebay\..+/, /bestbuy\..+/]; const currentHost = window.location.hostname; const isAllowed = allowedPatterns.some(pattern => pattern.test(currentHost)); if (!isAllowed) { return; // 直接退出,不执行后续扩展逻辑 } // 下面是你的扩展核心代码
内容的提问来源于stack exchange,提问作者gloopy-rocket
相关产品推荐
相关产品推荐

