Chrome Extension : Custom Protocol?
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:
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.
上一篇: 键入使用JavaScript
下一篇: Chrome扩展程序:自定义协议?