【发布时间】:2020-08-19 11:07:41
【问题描述】:
我正在开发一个与 Twitter 交互并在用户访问 twitter.com/home 时注入内容脚本的 Chrome 扩展程序。我在 manifest.json 中声明了 content_scripts,并且在 twitter.com/home 上一切正常。但是,当我访问 twitter.com 时,它会重定向到 twitter.com/home,并且扩展程序不会注入内容脚本。将“twitter.com”添加到 manifest.json 中的“matches”列表可以解决问题,但我希望扩展仅在 twitter.com/home 加载时注入脚本。我正在考虑使用 webNavigation API 来检测重定向,但我想知道是否有更有效的方法来实现这一点。谢谢!
manifest.json
"name": "xxx",
"version": "1.0",
"description": "abc",
"permissions": [
"activeTab",
"declarativeContent",
"storage"
],
"content_scripts": [
{
"matches": ["https://twitter.com/home", "https://twitter.com/"],
"run_at": "document_idle",
"js": ["script.js"]
}
],
"background": {
"scripts": ["background.js"],
"persistent": false
},
"manifest_version": 2
}
【问题讨论】:
-
另见this answer。