我注意到将 CSS 注入第三方页面的预期方式似乎无法正常工作。
相关的manifest.json部分:
"content_scripts": [
{
"matches": ["*://*.youtube.com/watch?v*"],
"css": ["css/youTubeInject.css"],
"all_frames": true,
"js": ["js/thirdParty/underscore.js", "js/thirdParty/jquery.js", "js/youTubeInject.js"]
}
]
在这里我声明我想将一些 CSS 和一些 JavaScript 注入到与 YouTube 正则表达式匹配的页面中。
我的 JavaScript 都注入得很好。我的 CSS 根本没有注入。我已经三重检查了文件位置和名称。
youTubeInject.js 的顶部包含:
$(function () {
var style = document.createElement('link');
style.rel = 'stylesheet';
style.type = 'text/css';
style.href = chrome.extension.getURL('css/youTubeInject.css');
document.head.appendChild(style);
这会导致我的 CSS 正确加载,并且是解决该问题的有效方法。
对于这个问题,有人有任何建议,或者我可以跟踪的错误吗?我们将不胜感激!
Chrome 在检查是否必须应用清单文件中声明的 CSS 文件时似乎会忽略查询字符串和位置片段。
http://www.youtube.com/watch?v=VIDEOID
被视为
http://www.youtube.com/watch
.
您的匹配模式包含查询字符串的一部分,这会导致模式根本不匹配。
目前,“matches”的行为不一致:
Documentation
Pattern : https://*.google.com/foo*bar
What it does: Matches (...) path starts with /foo and ends with bar
"js" in manifest file
Checks if pattern matches scheme://host/path?querystring
Example : https://google.com/foo?bar
Non-example : https://google.com/foobar?
"css" in manifest file
Checks if pattern matches scheme://host/path
Example : https://google.com/foobar?thisisignored
Non-example : https://google.com/foo?bar
In all cases, the location fragment (aka location hash) is ignored.
这个 bug 已经在 2 年前报告过,但没有及时发现:
- 问题 68561:清单 content_scripts“匹配”应用不一致 https://code.google.com/p/chromium/issues/detail?id=68561
还有另一个错误,可能相关,它有更多的追随者:
- 问题 100106:从内容脚本中排除域对于 CSS 文件不起作用 https://code.google.com/p/chromium/issues/detail?id=100106
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)