Web Activities vs Web Intents

In the last few days Mozilla have outlined their Web Activities API. This page compares the functionality of this new API with Google’s Web Intents API. The work on Web Activities is still at an early stage and it looks like they have yet to fully document it. The Mozilla wiki page frames their API design principles against Web Intents by stating the following:

"Web Activities is a counter-proposal to Web Intents. It is trying to limit the scope of the API to the following use case: APP A wants to delegate an activity to APP B. Web Activities isn't a discovery API or a communication API"

Although the list differences below looks substantial, for the vast amount of use cases you could easily build a JavaScript library to bridge both APIs. They have a lot more in common than they are different.

Core features comparison

Invoking an intent/activity

Invoking a Web Activity


var activity = new Activity({ 
   "name": "pick", 
   "data": { 
      "type": "image/png", 
      "multiple": false 
   }
});
activity.onsuccess = function() { 
    doSomethingWithImage(activity.result); 
});
activity.onerror = function(){ 
    alert("Failure when trying to pick an image!"); 
});

Invoking a Web Intent


var intent = new Intent({
   "action": "http://webintents.org/pick",
   "type": "image/png",
]);
navigator.startActivity(intent, pickOnSuccess, pickOnError);
function pickOnSuccess(data) {
  doSomethingWithImage(data);
}
function pickOnError(data) {
  alert("Failure when trying to pick an image!"); 
}
Creating an object of intent/activity properties
  Web Activities Web Intents
name/actions Exact match Exact match *a
data/type Similar *b Similar
extras   Yes
suggestions   Yes
services   Yes
transfer   Yes
Callbacks
  Web Activities Web Intents
navigator.startActivity Not needed Yes
onsuccess/onSuccess Similar *c Similar *c
onerror/onFailure Similar Similar
  1. Web Intents should always be a URL but, Web Activities can be namespaced with a URL or a simple verb.
  2. They are the same apart from the addition of a multiple property in Web Activities. This could be useful in creating the right type of pick UI in a service.
  3. It's interesting how the data object is passed into the function in intents where as Web Activities updates a results property on the activity object.

Handling an intent/activity request in a service

Handling a Web Activity request


navigator.setMessageHandler('activity', function(activity) {
   var image = getImageData();
   if (image) {
      activity.postResult({ type: "image/png", url: image });
   }else{
      activity.postError("NoImage");
   }
});

Handling a Web Intent request


if (window.intent) {
    var image = getImageData();
    if (image) {
        intent.postResult(image);
    }else{
        intent.postFailure("NoImage");
    }
}
Message posts
  Web Activities Web Intents
navigator.setMessageHandler Yes Not needed
postResult() Similar *a Similar *a
postError()/postFailure() Exact match Exact match

Registrating an intent/activity service

Registrating a Web Activity - JavaScript


navigator.registerActivityHandler({ 
   name: "pick", 
   href: "pickimage.html", 
   disposition: "inline",
   filters: { 
      type: ["image/png", "image/gif"] 
   }
});

Registrating a Web Intent - Tag


<intent 
   action="http://webintents.org/pick" 
   href="http://example.com/pickimage.html"
   disposition: "inline"
   type="image/png image/gif" 
   title="Pick a image" />
Manifest registration
  Web Activities Web Intents
name/actions Exact match Exact match *a
href Exact match Exact match
filters/types Similar Similar *b
title Yes *c
disposition Exact match Exact match
  1. Web Intents should always be a URL but, Web Activities can be namespaced with a URL or a simple verb.
  2. Web Intents has a more complex structure where the type has two parts ie text/uri-list;type=image/jpeg this allows you to specify a URI which is of a certain data type.
  3. Web Activities will most likely use the application title

Unregistrating an intent/activity service

Unregistrating a Web Activity - JavaScript


navigator.unregisterActivityHandler({ 
   name: "pick", 
   filters: { 
      type: ["image/png", "image/gif"] 
   }
});

Unregistrating a Web Intent - Tag


<intent />
Unregistrating
  Web Activities Web Intents
<intent />   Yes
unregisterActivityHandler Yes *a  
  1. With Web Intents a page/app can unregister itself implicitly by removing all intent tags, or by keeping the tag present, but without action or type attributes.

Is a intent/activity registrated

Is a Web Activity registrated


navigator.isActivityHandlerRegistered({ 
   name: "pick", 
   filters: { 
      type: ["image/png", "image/gif"] 
   }
});
Is handler registered
  Web Activities Web Intents
isActivityHandlerRegistered Yes *a
  1. Google has decided not to add an “isRegistered” type function because of the browser fingerprinting issue. This means they have had to add other ways of suggesting or defaulting to services so the user is not left high and dry by clicking links that do not have service options available.

Manifest registration

Web Activities manifest registration


 "activities": {
   "share": {
     "filters": {
       type: ["image/png", "image/gif"],
      }
     "href": "/shareimage.html",
     "disposition": "window"
   }
 }

Web Intents manifest registration


  "intents" : {
	"http://webintents.org/share" : [{
	"type" : ["image/png", "image/gif"],
    "path" : "/shareimage.html",
    "title" : "Share an image"
	}]
  }
Manifest registration
  Web Activities Web Intents
name/actions Exact match Exact match *a
path/href Exact match Exact match
filters/types Similar Similar *a
title Yes *b
disposition *c Yes
  1. Web Intents has a more complex structure where the type has two parts ie text/uri-list;type=image/jpeg this allows you to specify a URI which is of a certain data type.
  2. Web Activities will most likely use the application title
  3. Manifest registration is not a documented part of Web Intents, so I could not check if disposition is supported in this context, but disposition is supported in general.

Areas where the APIs differ:

  1. Google has decided not to add an “isRegistered” type function because of the browser fingerprinting issue. This means they have had to add other ways of suggesting or defaulting to services so the user is not left high and dry by clicking links that do not have service options available.
  2. Web Intents has a much broader concept of communication between apps/services. This can be seen in the fact it allows for “persistent connections” and the specification talks about registration of intents from outside the browser. Web Activities seems to have a narrower focus.
  3. Web Intents has a declarative HTML tag <intent> it wants to use to help with service discovery. Mozilla have mentioned reusing elements within the <head> tag to register an activity but they have stated they are not interested in general discovery.
  4. Web Activities has taken a different approach to how the data is returned. Their API allows you to specify the mime-type and also how the data is packaged. So an image could be a JPEG, but you also need to know whether the returning data is a URL for a JPEG or a Base64 encoded string. Web Intents does try to address this issue but in a different, less clear manner.
  5. Web Intents has an “extras” property which is a key-value dictionary of metadata that can be sent with requests. Web Activities does not have the concept of additional metadata