Copyright © 2019 the Contributors to the Web Share API - Level 2 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 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 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 Level 2 spec. It it subject to review and changes.
This section is non-normative.
This example shows a basic share operation. In response to a button click, this JavaScript code shares the current page's URL.
shareButton.addEventListener("click", async () => {
try {
await navigator.share({ title: "Example Page", url: "" });
console.log("Data was shared successfully");
} catch (err) {
console.error("Share failed:", err.message);
}
});
Note
that
a
url
of
''
refers
to
the
current
page
URL,
just
as
it
would
in
a
link.
Any
other
absolute
or
relative
URL
can
also
be
used.
In
response
to
this
call
to
navigator.share()
,
the
user
agent
would
display
a
picker
or
chooser
dialog,
allowing
the
user
to
select
a
target
to
share
this
title
and
the
page
URL
to.
The following are defined in [ WEBIDL ]:
TypeError
is
defined
by
[
ECMASCRIPT
].
This section is non-normative.
Web Share enables data to be sent from websites to native applications. While this ability is not unique to Web Share, it does come with a number of potential security issues that can vary in severity (depending on the underlying platform).
navigator.share()
,
because
this
information
could
be
used
for
fingerprinting,
as
well
as
leaking
details
about
the
user's
device.
navigator.share()
is
rejected.
Even
distinguishing
between
the
case
where
no
targets
are
available
and
user
cancellation
could
reveal
information
about
which
apps
are
installed
on
the
user's
device.
navigator.share()
presents
the
user
with
a
dialog
asking
them
to
select
a
target
application
(even
if
there
is
only
one
possible
target).
This
surface
serves
as
a
security
confirmation,
ensuring
that
websites
cannot
silently
send
data
to
native
applications.
navigator.share()
is
available
only
in
secure
contexts
(such
as
https://
schemes).
navigator.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
disable
the
feature
entirely
when
in
a
private
browsing
mode,
but
this
is
not
mandated
as
the
chooser
UI
could
be
considered
sufficient
warning.
navigator.share()
might
be
used
to
exploit
buffer
overflow
or
other
remote
code
execution
vulnerabilities
in
native
applications
that
receive
shares.
There
is
no
general
way
to
guard
against
this,
but
implementors
will
want
to
be
aware
that
it
is
a
possibility.
This section is non-normative.
The
Web
Share
API
is
designed
to
be
extended
in
the
future
by
way
of
new
members
added
to
the
ShareData
dictionary,
to
allow
both
sharing
of
new
types
of
data
(
e.g.
,
images
)
and
strings
with
new
semantics
(
e.g.
author).
The
three
members
title
,
text
,
and
url
,
are
part
of
the
base
feature
set,
and
implementations
that
provide
navigator.share()
need
to
accept
all
three.
Any
new
members
that
are
added
in
the
future
will
be
individually
feature-detectable
,
to
allow
for
backwards-compatibility
with
older
implementations
that
don't
recognize
those
members.
These
new
members
might
also
be
added
as
optional
"
MAY
"
requirements.
The
share()
method
returns
a
rejected
promise
with
a
TypeError
if
none
of
the
specified
members
are
present.
The
intention
is
that
when
a
new
member
is
added,
it
will
also
be
added
to
this
list
of
recognized
members.
This
is
for
future-proofing
implementations:
if
a
web
site
written
against
a
future
version
of
this
spec
uses
only
new
members
(
e.g.
,
navigator.share({image:
x})
),
it
will
be
valid
in
future
user
agents,
but
a
TypeError
on
user
agents
implementing
an
older
version
of
the
spec.
Developers
will
be
asked
to
feature-detect
any
new
members
they
rely
on,
to
avoid
having
errors
surface
in
their
program.
Editors of this spec will want to carefully consider the genericity of any new members being added, avoiding members that are closely associated with a particular service, user agent or operating system, in favour of members that can potentially be applied to a wide range of platforms and targets.
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.
canShare()
has
been
added.
ShareData
dictionary
now
has
a
files
member
for
sharing
files.