我可以使用 JavaScript(用户脚本)修改 chrome://extensions/ 页面吗?
我想使用 JavaScript 为 chrome://extensions/
页面添加搜索栏,因此我创建了一个名为 test.user.js 的文件,并在其中编写脚本:
// ==UserScript==
// @name chromeex
// @namespace chromeex
// @version v1.0
/* @reason
* just a test
* @end
*/
// @match chrome://extensions/
//
// ==/UserScript==
(function(){
alert("haha");
}());
但是当我加载时在 Chrome 中,它说 Invalid header,最后我发现是 @match chrome://extensions/
导致了错误。有解决这个问题的方法吗?
I'd like to use JavaScript to add a search bar for chrome://extensions/
page, so I created a file called test.user.js, and write scripts in it:
// ==UserScript==
// @name chromeex
// @namespace chromeex
// @version v1.0
/* @reason
* just a test
* @end
*/
// @match chrome://extensions/
//
// ==/UserScript==
(function(){
alert("haha");
}());
But when I load it in Chrome, it said Invalid header, finally I found out that it's @match chrome://extensions/
that cause the error. Is there a walkaround for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Chrome 扩展程序不会在
chrome://extensions/
目录或 上执行Chrome 网上应用店或其他一些重要的安全区域。一种简单的思考方法是,如果扩展程序可以访问 Chrome 扩展程序页面中的 DOM,它可能会导致您无法卸载它,这对许多用户来说可能非常讨厌。不过,如果您愿意,您可能需要查看 chrome.management API在“扩展”页面之外构建一些内容,以便能够搜索用户的扩展。
chrome
本身不是允许的方案,这就是您收到无效方案错误的原因。 以下是 Google 对此的说法:因此,根据定义,
chrome
作为一种方案无论如何都行不通。不要将其视为另一个网页,而是 Chrome 用户界面的一部分。A Chrome extension won't execute in the
chrome://extensions/
directory or on the Chrome Web Store or a few other important areas for security.One easy way to think of it is that if an extension had access to the DOM in your Chrome Extensions page it could remove your ability to uninstall it, which could be pretty nasty for many users. You may want to look at the chrome.management API, however, if you want to build something outside the Extensions page to be able to search through a user's extensions.
chrome
itself is not a permitted scheme, which is why you are getting an invalid scheme error. Here's what Google has to say about it:So by definition
chrome
as a scheme will not work no matter what. Think of it not as just another web page, but a part of Chrome's UI.由于安全原因,您无法在 chrome://extensions/ 中注入内容脚本/用户脚本。您可以使用Extension Management API页面创建您自己的扩展程序管理扩展程序。
You cannot inject a Content Script / User Script in chrome://extensions/ due to security reasons. You can use the Extension Management API page to create your own extension management extension.
我认为,该页面不是“普通”网页,它是高安全区域,您不能在其中乱搞用户脚本。这就是插件的用途。
I think, that page is not "ordinary" web page, it's high security area, where you can't mess around with userscripts. That is what plugins are for.