Copyright © 2018 the Contributors to the Web Share Target API Specification, published by the Web Incubator Community Group under the W3C Community Contributor License Agreement (CLA). A human-readable summary is available.
This specification defines an API that allows websites to declare themselves as web share targets, which can receive shared content from either the Web Share API, or system events (e.g., shares from native apps).
This is a similar mechanism to navigator.registerProtocolHandler
,
in that it works by registering the website with the user agent, to
later be invoked from another site or native application via the
user agent (possibly at the discretion of the user). The difference is
that registerProtocolHandler
registers the handler via a programmatic API, whereas a Web Share
Target is declared in the Web App
Manifest, to be registered at a time of the user agent or user's
choosing.
This specification was published by the Web Incubator Community Group. It is not a W3C Standard nor is it on the W3C Standards Track. Please note that under the W3C Community Contributor License Agreement (CLA) there is a limited opt-out and other conditions apply. Learn more about W3C Community and Business Groups.
This is an early draft of the Web Share Target spec.
In order to implement this API, it is REQUIRED that the user agent implements Web App Manifest. This spec also re-uses some definitions from the Web Share API spec. Implementation of that spec is NOT REQUIRED to implement this one (but it is RECOMMENDED).
This section is non-normative.
To register a site as a share target, a share_target
entry is
added to the Web App Manifest, as shown:
{
"name": "Includinator",
"share_target": {
"action": "share.html",
"params": {
"title": "name",
"text": "description",
"url": "link"
}
}
}
The params keys correspond to the key names in ShareData, while the values are arbitrary names that will be used as query parameters when the target is launched.
When a share takes place, if the user selects this app as the share
target, the user agent creates a GET request like a form submission, and
opens a new browsing context using the action
URL.
For the purpose of this example, we assume the manifest is located at
https://example.org/includinator/manifest.webmanifest
.
<html>
<head>
<link rel="manifest" href="manifest.webmanifest">
</head>
<body>
<script>
window.addEventListener('load', () => {
var parsedUrl = new URL(window.location.toString());
console.log('Title shared: ' + parsedUrl.searchParams.get('name'));
console.log('Text shared: ' + parsedUrl.searchParams.get('description'));
console.log('URL shared: ' + parsedUrl.searchParams.get('link'));
});
</script>
</body>
</html>
If an incoming share contains the title "My News" and the URL
http://example.com/news
, the user agent will open a new
window or tab and navigate to:
https://example.org/includinator/share.html?name=My%20News&description=&link=http%3A%2F%2Fexample.com%2Fnews
How the handler deals with the shared data is at the handler's discretion, and will generally depend on the type of app. Here are some suggestions:
title
as the subject of an email, with text
and url
concatenated together as the body.
title
, using text
as the body of the message
and adding url
as a link. If text
is missing,
it might use url
in the body as well. If url
is missing, it might scan text
looking for a URL and add
that as a link.
title
and using text
and url
concatenated together. It might truncate the text or replace
url
with a short link to fit into the message size.
The following IDL extends the WebAppManifest
dictionary.
partial dictionary WebAppManifest
{
};
The following steps are added to the extension point in the steps for processing a manifest:
share_target
"] to the result of
running post-processing the share_target
member
given manifest["share_target
"],
manifest["scope
"], and
manifest URL.
This section is non-normative.
This section is non-normative.
Thanks to the Web Intents team, who laid the groundwork for the web app interoperability use cases. In particular, Paul Kinlan, who did a lot of early advocacy for Web Share and Web Share Target.
Thanks to Connie Pyromallis, who wrote an early draft of this spec, and helped design and prototype the API.
Thanks to Alex Russell and David Baron, for their feedback on early drafts of this spec.