Chrome扩展程序:自定义协议? [英] Chrome Extension : Custom Protocol?
问题描述
const kSIMPLEURI_CONTRACTID =是否有方法使用google chrome扩展名注册自定义协议? @ mozilla.org /网络/简单-URI; 1\" ;
const kIOSERVICE_CONTRACTID =@ mozilla.org / network / io-service; 1;
const nsISupports = Components.interfaces.nsISupports;
const nsIIOService = Components.interfaces.nsIIOService;
const nsIProtocolHandler = Components.interfaces.nsIProtocolHandler;
const nsIURI = Components.interfaces.nsIURI;
我想要协议:
xyz :
不是xyz://
这可能吗?
有一些方法可以模拟这些行为:
xyz:...
的链接点击。 使用 webRequest
API截取并将所有请求从默认搜索提供程序重定向到自定义URL。我使用这种方法来捕获通配符搜索关键字,但它也可以用于支持伪造方案。不幸的是,扩展名对于用户的搜索设置是非常具体的,因为它会做这样的事情:
重定向http:/ /google.com/search?q=xyz%3Awhatever
chrome-extension://.../whatever
在这两种情况下,在多功能框中不会看到 xyz:whatever
navigator.registerProtocolHandler
应该是注册 xyz的最佳方式:
处理程序。不幸的是,目前它非常有限。自定义协议必须以 web +
为前缀。另请参阅此API的开放错误列表 。
Are there methods to register a custom protocol with a google chrome extension like you can in firefox :
const kSIMPLEURI_CONTRACTID = "@mozilla.org/network/simple-uri;1";
const kIOSERVICE_CONTRACTID = "@mozilla.org/network/io-service;1";
const nsISupports = Components.interfaces.nsISupports;
const nsIIOService = Components.interfaces.nsIIOService;
const nsIProtocolHandler = Components.interfaces.nsIProtocolHandler;
const nsIURI = Components.interfaces.nsIURI;
I want the protocol:
xyz:
Not xyz://
Is this possible?
Chrome does not offer a way to set custom handlers for the xyz:
scheme.
There are some ways to emulate the behavior though:
- Use Content scripts to set up an event listener for clicks on links which point to
xyz:...
. Use the
webRequest
API to intercept and redirect all requests from the default search provider to a custom URL. I'm using this method for catching wildcard search keywords, but it can also be used for supporting fake schemes. Unfortunately, the extension would be quite specific to the user's search settings, because it would do something like this:Redirect http://google.com/search?q=xyz%3Awhatever to chrome-extension://.../whatever
in both cases, you won't see xyz:whatever
in the omnibox, though.
navigator.registerProtocolHandler
should be the best way to register a xyz:
handler. Unfortunately, it is quite limited at the moment. Custom protocols must be prefixed with web+
. Also take a look at the list of open bugs for this API.
这篇关于Chrome扩展程序:自定义协议?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!