W3cubDocs

/Web APIs

Navigator: registerProtocolHandler() method

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

The Navigator method registerProtocolHandler() lets websites register their ability to open or handle particular URL schemes (aka protocols).

For example, this API lets webmail sites open mailto: URLs, or VoIP sites open tel: URLs.

Syntax

js

registerProtocolHandler(scheme, url)

Parameters

scheme

A string containing the permitted scheme for the protocol that the site wishes to handle. For example, you can register to handle SMS text message links by passing the "sms" scheme.

url

A string containing the URL of the handler. %s, as a placeholder that will be replaced with the escaped URL to be handled.

Note: The handler URL must use the https scheme. Older browsers also supported http.

Return value

None (undefined).

Exceptions

SecurityError DOMException

The user agent blocked the registration. This might happen if:

  • The registered scheme (protocol) is invalid, such as a scheme the browser handles itself (https:, about:, etc.)
  • The handler URL's origin does not match the origin of the page calling this API.
  • The browser requires that this function is called from a secure context.
  • The browser requires that the handler's URL be over HTTPS.
SyntaxError DOMException

The %s placeholder is missing from the handler URL.

Permitted schemes

For security reasons, registerProtocolHandler() restricts which schemes can be registered.

A custom scheme may be registered as long as:

  • The custom scheme's name begins with web+
  • The custom scheme's name includes at least 1 letter after the web+ prefix
  • The custom scheme has only lowercase ASCII letters in its name.

For example, web+burger, as shown in the Example below.

Otherwise, the scheme must be one of the following:

  • bitcoin
  • ftp
  • ftps
  • geo
  • im
  • irc
  • ircs
  • magnet
  • mailto
  • matrix
  • mms
  • news
  • nntp
  • openpgp4fpr
  • sftp
  • sip
  • sms
  • smsto
  • ssh
  • tel
  • urn
  • webcal
  • wtai
  • xmpp

Examples

If your site is burgers.example.com, you can register a protocol handler for it to handle web+burger: links, like so:

js

navigator.registerProtocolHandler(
  "web+burger",
  "https://burgers.example.com/?burger=%s",
);

This creates a handler that lets web+burger: links send the user to your site, inserting the accessed burger URL into the %s placeholder.

This script must be run from the same origin as the handler URL (so any page at https://burgers.example.com), and the handler URL must be http or https.

The user will be notified that your code asked to register the protocol handler, so that they can decide whether or not to allow it. See the screenshot below for an example on google.co.uk:

A browser notification reads "Add Burger handler (www.google.co.uk) as an application for burger links?", and offers an "Add Application" button and a close to ignore the handler request.

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
registerProtocolHandler
13From Chrome 77, the URL parameter only accepts http or https URLs.
79 2 No 11.6 No No No 4 No No No
scheme_parameter_bitcoin 28 79 2 No 15 No No No 4 No No No
scheme_parameter_cabal 86 86 No No 72 No No No No No No No
scheme_parameter_dat 86 86 No No 72 No No No No No No No
scheme_parameter_did 86 86 No No 72 No No No No No No No
scheme_parameter_dweb 86 86 No No 72 No No No No No No No
scheme_parameter_etherium 86 86 No No 72 No No No No No No No
scheme_parameter_ftp No No 98 No No No No No 98 No No No
scheme_parameter_ftps No No 98 No No No No No 98 No No No
scheme_parameter_geo 30 79 2 No 17 No No No 4 No No No
scheme_parameter_hyper 86 86 No No 72 No No No No No No No
scheme_parameter_im 30 79 2 No 17 No No No 4 No No No
scheme_parameter_ipfs 86 86 No No 72 No No No No No No No
scheme_parameter_ipns 86 86 No No 72 No No No No No No No
scheme_parameter_irc 15 79 2 No 11.6 No No No 4 No No No
scheme_parameter_ircs 30 79 2 No 17 No No No 4 No No No
scheme_parameter_magnet 30 79 2 No 17 No No No 4 No No No
scheme_parameter_mailto 13 79 2 No 11.6 No No No 4 No No No
scheme_parameter_matrix 92 92 90 No 78 No No No 90 No No No
scheme_parameter_mms 13 79 2 No 11.6 No No No 4 No No No
scheme_parameter_news 13 79 2 No 11.6 No No No 4 No No No
scheme_parameter_nntp 13 79 2 No 11.6 No No No 4 No No No
scheme_parameter_openpgp4fpr 42 79 2 No 29 No No No 4 No No No
scheme_parameter_sftp No No 98 No No No No No 98 No No No
scheme_parameter_sip 30 79 2 No 17 No No No 4 No No No
scheme_parameter_sms 13 79 2 No 11.6 No No No 4 No No No
scheme_parameter_smsto 26 79 2 No 15 No No No 4 No No No
scheme_parameter_ssb 86 86 No No 72 No No No No No No No
scheme_parameter_ssh 41 79 2 No 28 No No No 4 No No No
scheme_parameter_tel 13 79 2 No 11.6 No No No 4 No No No
scheme_parameter_urn 13 79 2 No 11.6 No No No 4 No No No
scheme_parameter_webcal 13 79 2 No 11.6 No No No 4 No No No
scheme_parameter_wtai 31 79 2 No 18 No No No 4 No No No
scheme_parameter_xmpp 30 79 2 No 17 No No No 4 No No No
secure_context_required 80 79 62 No 67 No No No No No No No

See also

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Navigator/registerProtocolHandler