title: Where to call navigator.registerProtocolHandler?
body: <p><strong>How and where do I use navigator.registerProtocolHandler to make it work?</strong></p>
  
  <p>.</p>
  
  <p><a href="https://stackoverflow.com/questions/7087728/custom-protocol-handler-in-chrome">This topic</a> suggests you can call the following function to add the custom protocol handler:</p>
  
  <pre><code>navigator.registerProtocolHandler('web+custom', 'http://example.com/rph?q=%s', 'My App');
  </code></pre>
  
  <p>When I call it from the console, I get the </p>
  
  <pre><code>Uncaught DOMException: Failed to execute 'registerProtocolHandler' on 'Navigator': 
  Can only register custom handler in the document's origin.
  </code></pre>
  
  <p>This also happens if I include it as a part of a content script as suggested <a href="https://developer.mozilla.org/en/docs/Web-based_protocol_handlers" rel="noreferrer">here</a></p>
  
  <p><strong>install_protocol.html</strong></p>
  
  <pre><code>&lt;head&gt;
    &lt;title&gt;Web Protocol Handler Sample - Register&lt;/title&gt;
    &lt;script type="text/javascript"&gt;
      navigator.registerProtocolHandler("burger",
                                "http://www.google.co.uk/?uri=%s",
                                "Burger handler");
    &lt;/script&gt;
  &lt;/head&gt;
  </code></pre>
  
  <p>I also tried calling it in my <em>background.js</em> script, where it didn't give the error, however the protocol doesn't seem to respond.</p>
  
  <p>.</p>
  
  <p>Could you explain how to go through the process of registering and using a custom protocol in Chrome?</p>