Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Intent Scheme

Paul Frazee edited this page Jul 1, 2017 · 13 revisions

What are intents?

Intents are special URIs used for creating interactions between Web apps. Their use ranges from opening a page, to editing a photo, to publishing a blog post. They are designed to maximize interactivity with minimal effort by users or developers.

An intent looks like this:

intent:share?type=text/html&url=https://github.com/beakerbrowser/beaker/wiki/Intent-Scheme

Intents are used like regular URLs, and can be used as the destination of forms.

<a href="intent:view?type=image/png&url=dat://.../cat.png">My cat!</a>

Any values POSTed in a form body are added as the parameters to the intent. This enables you to create convenient cross-domain form flows.

<form action="intent:publish" method="POST">
  <input type="hidden" name="url" value="dat://.../cat.png">
  <input type="text" name="Title">
  <button type="submit">Publish</button>
</form>

However, an intent is not usable via Ajax! This is because all intents result in a 302 redirect to the handling application. The handling application is given the parameters, and it displays a "confirm" screen. Upon confirmation, the application handles the action.

Details

URL Spec

Intent URIs consist of an identifier, followed by a series of one or more parameters, the order of which is not significant, formatted in the same way as query strings that ordinarily terminate HTTP URLs.

intent = 'intent:' identifier query-params?
identifier = [a-z][a-z-]*

The URI identifier signifies which intent action is being specified. Example identifiers might include "share", "edit", "view", "subscribe", "contact", and "publish".

Intent "Handlers"

TODO - installation, and routing of intent URLs to handlers. For reference see Android: Intent Resolution and WebActivities: Declarative Registration

Intent API

For convenience, the browser will include a JS api for constructing and parsing intent URLs.

var intent = new IntentURI('publish')
intent.set('title', 'Intent Scheme Spec')
intent.set('type', 'text/html')
intent.set('url', 'https://github.com/beakerbrowser/beaker/wiki/Intent-Scheme')
console.log(intent.toString())
// => 'intent:share?title=Intent%20Scheme%20Spec&type=text/html&url=https://github.com/beakerbrowser/beaker/wiki/Intent-Scheme'

No "return to caller"

An intent handler is always opened as a new page, and may be opened in a new tab using target="_blank". It has no defined life-cycle or expectation of a "return value." The calling page should not expect feedback from the intent.

History

The concept of intents on the Web has three notable precedents. The first is the informal service implementations, such as Twitter's Web Intents. The second is a now-dead Chrome WebIntents API. The third is a now-dead Firefox Web Activities API. It's worth nothing that mobile OSes have a history of using intents (Android, iOS).

All of these implementations have had an influence on this spec, but ultimately this spec is more in keeping with Twitter's interpretation of Web Intents.

Relationship to the App Scheme Spec

The "Application Scheme" was a naming-system, whereby users could assign dat:// applications to URLs such as app://mail or app://news. It was rejected due to the "rampant 404s problem", which was this:

Without coordination, application authors will follow different standards for their URLs. E.g. Despite Bob and Alice having an app://mail installed, Bob cannot share app://mail/latest, because Alice's installed app://mail does not implement that URL. 404s would become a common symptom of that lack of coordination.

The Intents Scheme solves this with two changes:

  • URLs are "redirect-based." The URL intent:share will redirect to a dat:// application using a 3xx code.
  • URLs are "parameterized." Rather than intent:mail/user/bob, it's intent:mail?user=bob.

Parameterized URLs include enough information to provide effective fallback behaviors. Multiple apps can be queried for support of the intent URL, and a default application may be included in the URL itself.