Skip to content

Commit 68494b7

Browse files
Add canShare() method (#177)
1 parent 1904b8f commit 68494b7

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

index.html

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,25 @@

9292
display a picker or chooser dialog, allowing the user to select a
9393
target to share this title and the page URL to.
9494
p>
95+
<p>
96+
Calling {{Navigator/canShare()}} method with a {{ShareData}} dictionary
97+
[=validate share data|validates=] the shared data. unlike
98+
{{Navigator/share()}}, it can be called without [=transient
99+
activation=].
100+
p>
101+
<pre class="js example">
102+
const file = new File([], "some.png", { type: "image/png" });
103+
104+
// Check if files are supported
105+
if (navigates.canShare({files: [file]})) {
106+
// Sharing a png file would probably be ok...
107+
}
108+
109+
// Check if a URL is ok to share...
110+
if (navigates.canShare({ url: someURL })) {
111+
// The URL is valid and can probably be shared...
112+
}
113+
pre>
95114
section>
96115
<section>
97116
<h2>
@@ -104,6 +123,8 @@

104123
<pre class="idl">
105124
partial interface Navigator {
106125
[SecureContext] Promise<undefined> share(optional ShareData data = {});
126+
127+
[SecureContext] boolean canShare(optional ShareData data = {});
107128
};
108129
pre>
109130
<p>
@@ -257,6 +278,25 @@

257278
or bypassing the UI if there is only a single share target.
258279
div>
259280
section>
281+
<section>
282+
<h3>
283+
`canShare(data)` method
284+
h3>
285+
<p>
286+
When the <dfn>canShare(data)dfn> method is called with argument
287+
{{ShareData}} |data:ShareData|, run the following steps:
288+
p>
289+
<ol class="algorithm">
290+
<li>If the [=current settings object=]'s [=environment settings
291+
object/responsible document=] is not <a>allowed to usea>
292+
<a>"web-share"a>, return false.
293+
li>
294+
<li>Return the result of [=validate share data=] with |data| and
295+
[=this=]'s [=relevant settings object=]'s [=environment settings
296+
object/API base URL=].
297+
li>
298+
ol>
299+
section>
260300
<section>
261301
<h3>
262302
Validate share data

0 commit comments

Comments
 (0)