How to declare Chrome extension to handle specific

2019-04-28 14:50发布

问题:

I'd like to write an extension that handles specific URLs that have custom scheme (myscheme://). How do I declare my extension so it is invoked on such a request and intercepts it? (The URL can be clicked, typed directly in the address bar, passed in the command line, etc.). This is probably a beginner question, but I'm a beginner!

回答1:

There is a JavaScript API that you can use for this.

navigator.registerProtocolHandler("mailto",
                                  "https://www.example.com/?uri=%s",
                                  "Example Mail");