See also translations.
Copyright © 2023 World Wide Web Consortium. W3C® liability, trademark and permissive document license rules apply.
This specification defines an API for sharing text, links and other content to an arbitrary destination of the user's choice.
The available share targets are not specified here; they are provided by the user agent. They could, for example, be apps, websites or contacts.
This section describes the status of this document at the time of its publication. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at https://www.w3.org/TR/.
This document was published by the Web Applications Working Group as a Recommendation using the Recommendation track.
W3C recommends the wide deployment of this specification as a standard for the Web.
A W3C Recommendation is a specification that, after extensive consensus-building, is endorsed by W3C and its Members, and has commitments from Working Group members to royalty-free licensing for implementations. Future updates to this Recommendation may incorporate new features.
This document was produced by a group operating under the W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.
This document is governed by the 2 November 2021 W3C Process Document.
This section is non-normative.
The ability to share content is often dependent on the underlying operating system providing a "share" capability and also on OS UI conventions. For example, some OSs present a "share sheet", while others rely on an pop-up menu. Due to these aforementioned dependencies, there is ongoing work by implementers to bring the Web Share API to all OSs. This ongoing effort is reflected as failures in the implementation report, which is generated by running tests on a limited set of OSs. However, the Working Group is optimistic that the Web Share API will become more available across all OSs over time, and is already widely available on popular OSs across a range of devices.
This section is non-normative.
Because of how WebIDL dictionaries work, members passed to
share
()
that are unknown to the user agent are ignored.
This can be a problem when sharing multiple members, but the user agent
doesn't support sharing one of those members. To be sure that every
member being passed is supported by the user agent, you can pass them
to canShare
()
individually to check if they are
supported.
Alternatively, you can adjust application's UI to not show UI components for unsupported members.
const data = {
title: "Example Page",
url: "https://example.com",
text: "This is a text to share",
someFutureThing: "some future thing",
};
// Things that are not supported...
const unsupported = Object.entries(data).filter(([key, value]) => {
return !navigator.canShare({ [key]: value });
});
The default allowlist of 'self' makes Web Share API available by default only in first-party contexts.
Third-party can be allowed to use this API via an iframe
's
allow
attribute:
Alternatively, the API can be disabled in a first-party context by specifying an HTTP response header:
See the Permissions Policy specification for more details and for how to control the permission policies on a per-origin basis.
This specification defines a policy-controlled permission identified by
the string "web-share"
. Its
default allowlist is 'self', which means third-party contexts are not allowed to use the API by default.
It is OPTIONAL for user agents to support Permissions Policy's
Permissions-Policy
HTTP header.
Developers can use the means afforded by the Permissions Policy specification to control if and when a third-party context is allowed to use this API.
This section is non-normative.
When this specification is used to present information in the user
interface, implementors will want to follow the OS level accessibility
guidelines for the platform. Further, as sharing can have potential
security implications for end-users, as outlined as part of the
share
()
method, the share UI needs to be presented in an
accessible manner, while also taking into consideration a platform's
security guidelines for user interfaces. Some key considerations are
to:
Together, these elements can help users with a range of visual, motor or cognitive disabilities to better understand the nature of the content being shared by a web page.
share
()
. This is to prevent leaking information that
could be used for fingerprinting, as well as leaking details about the
user's device or user's preferred share targets.
share
()
from a private browsing mode
might leak private data to a third-party application that does not
respect the user's privacy setting. User agents could present
additional warnings or MAY disable the feature entirely when in a
private browsing mode, but this is not mandated as the chooser UI could
be considered sufficient warning.
As well as sections marked as non-normative, all authoring guidelines, diagrams, examples, and notes in this specification are non-normative. Everything else in this specification is normative.
The key words MAY, MUST, OPTIONAL, and SHOULD in this document are to be interpreted as described in BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here.
WebIDLpartial interface Navigator {
[SecureContext] Promise<undefined> share
(optional ShareData
data = {});
[SecureContext] boolean canShare
(optional ShareData
data = {});
};
dictionary ShareData
{
sequence<File> files
;
USVString title
;
USVString text
;
USVString url
;
};
This section is non-normative.
The following normative changes were made to the specification during the Proposed Recommendation phase. Please see the commit log for a complete list of changes.
The following normative changes were made to the specification since it was published as a First Public Working Draft to Candidate Recommendation. Please see the commit log for a complete list of changes.
The editors would like to thank the following W3C groups for their invaluable feedback, which greatly improved this specification: Accessible Platform Architectures Working Group, the Internationalization Working Group, the Privacy Interest Group, and the Technical Architecture Group.
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.