我可以使用JavaScript(用户脚本)修改chrome:// extensions / page吗? [英] Can I modify chrome://extensions/ page with JavaScript(user script)?

查看:92
本文介绍了我可以使用JavaScript(用户脚本)修改chrome:// extensions / page吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用JavaScript为 chrome:// extensions / 页面添加搜索栏,所以我创建了一个名为test.user.js的文件,并且写脚本:

  // == UserScript == 
// @name chromeex
/ / @namespace chromeex
// @version v1.0
/ * @reason
*只是一个测试
* @end
* /
// @match chrome:// extensions /
//
// == / UserScript ==

(function(){
alert(haha);
}());

但是当我在Chrome中加载时,它表示无效标题,最后我发现它是 @match chrome:// extensions / 导致错误。是否有这样的解决方案?

解决方案

Chrome扩展程序不会在 chrome:/ / extensions / 目录或 Chrome网上应用店或其他几个重要的安全领域。

一个简单的方法就是,如果扩展程序可以访问Chrome扩展程序页面中的DOM,则可能会导致您无法卸载它,这对许多用户来说可能是非常讨厌的。您可能想查看 chrome.management API ,但是,如果您希望在扩展页面外部构建一些能够搜索用户扩展的内容。



chrome 本身不是一个允许的方案,这就是为什么你得到一个无效的方案错误。 以下是Google对此的评论


匹配模式本质上是一个以允许的方案开始的URL( http https 文件 ftp ),并且可以包含'*'字符。特殊模式< all_urls> 匹配任何以允许方案开头的网址。




因此,按照定义 chrome 作为一个方案无论如何都是行不通的。把它看作不仅仅是另一个网页,而是Chrome UI的一部分。


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?

解决方案

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:

A match pattern is essentially a URL that begins with a permitted scheme (http, https, file, or ftp), and that can contain '*' characters. The special pattern <all_urls> matches any URL that starts with a permitted scheme.

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.

这篇关于我可以使用JavaScript(用户脚本)修改chrome:// extensions / page吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆