Skip to content
A WebIntents like implementation based on a skeleton from Ian Hickson
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


This is an implementation of a WebIntents-like API, as sketched out by Ian Hickson in

This is implemented as a pure-JS shim - pages need only load intents.js and they can function as an invoker of intent or as a handler of intents. A rough outline of how it hangs together is:

  • intents.js arranges to create a hidden iframe back to localhost:8888 and uses a jschannel to communicate for registration and unregistration. localStorage on this host is the "repository".
  • When client code calls invokeIntent(), the picker is displayed an a jschannel created between the client code and the picker.
  • The picker loads the intent handlers in an iframe and yet another jschannel exists between the picker and the handler. Thus, the picker acts as a kind of relay - when the client communicates with the handler it goes over its jschannel to the picker, which then relays it over the jschannel to the handler.

As Firefox doesn't implement MessagePorts yet, a simple port-like javascript object is used.

Running the demo

  • Start in the root of this tree. This will start a http server on port 8888.
  • Open http://localhost:8888/handlers/sample_handler.html in your browser. Not much will happen but it should call registerIntentHandler to register that page as a handler for a 'share' intent. Close the page.

We also use the Firefox Share addon as an OAuth helper for the google etc plugins. This takes a few steps.

You should now see the picker with the 2 handlers displayed in tabs. The google service should be fully functional - ie, you can login and send an email.

Notable differences from Hixie's sketch

Instead of:

var port = navigator.handleIntent(intent, filter);  
port.onmessage = function (event) { handle( };  

we use a callback approach:

navigator.handleIntent(intent, filter, function(port) {  
   port.onmessage = function (event) { handle( };  

This is done as it make take some time for the UI to select an intent handler and we want to avoid blocking the main thread.

Similarly, registerIntentHandler, isIntentHandlerRegistered and unregisterIntentHandler take a callback, although this was done for pragmatic reasons - the shim uses postMessage to a server for the respository implementation.

You can’t perform that action at this time.