Over a million developers have joined DZone.

Web Share Target API

DZone 's Guide to

Web Share Target API

We take a look at the new Share Target API that was recently introduced by Google that makes it easier for bidirectional data flow between the web and apps.

· Integration Zone ·
Free Resource

I’m constantly worried that on the web platform we are creating unintended silos by making it harder to get data in and out of websites and apps, more importantly, I worry that the data only flows one way: from the web to apps, because apps can be in all the places that users expect them to be on their devices.

I was pretty pleased that Chrome started to work on the Share Target API that complements the work on navigator.share. Where navigator.share lets you share information out of your website to any app on the user's device that can receive ‘shares’ (Intent.ACTION_SEND in Android parlance), the Web Share Target lets your website (or PWA) say ‘I want to play in that game too.’

I’m pretty pleased to say that this work is now available in Chrome on Android.

The Web Share Target API is a small API that you define in your Web App Manifest. If you have ever used registerProtocolHandler you will see that it’s not a million miles away — you define a URL template that has a number of variables in that will be substituted when the user invokes the action.

First, you create an ‘object’ property called share_target that contains one property called url_template that has the path that should be opened when the user chooses our service. On Android, you can use the three substitution names called:

  • {title} - equivelent to .title on the navigator.share API, or Intent.EXTRA_SUBJECTfrom an Android Intent.
  • {text} - equivelent to .text on the navigator.share API, or Intent.EXTRA_TEXT from an Android Intent.
  • {url} - equivelent to .url on the navigator.share API, or the raw data from an Android Intent.

You can try this today by installing Twitter’s PWATwitter’s manifest is below:

    "name": "Twitter Lite",
    "share_target": {
        "url_template": "compose/tweet?title={title}&text={text}&url={url}"

Right now there are some limitations:

  • You can only have one per manifest, that means, in Twitter’s case, they can’t have a ‘Share to DM.’
  • There are some extensions proposed such as a service worker event callednavigator.actions that will be triggered without having to open up a UI surface, but they are not implemented yet.
  • You can only share ‘text,’ which means if you want to share a Blob of data you need to save that with a URL that would then be shared out.
  • It only works on Android.
  • You have to have the PWA installed, so you can’t do a drive-by registration of a share target. When Chrome generates a ‘Web APK’ it now looks at theshare_target to see if it should register the native <intent-filter>.
  • It’s not standardized yet as part of the manifest spec. Oh, and it also might change.

Limitations aside, this is a rather amazing addition to the web platform that is the start of breaking down the huge barriers of the web with regards to the integration on the host platforms.

If you want to track updates to this API, check out Chrome Status.

integration ,web api ,api integration

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}