|
92 | 92 | display a picker or chooser dialog, allowing the user to select a
|
93 | 93 | target to share this title and the page URL to.
|
94 | 94 | </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> |
95 | 114 | </section>
|
96 | 115 | <section>
|
97 | 116 | <h2>
|
|
104 | 123 | <pre class="idl">
|
105 | 124 | partial interface Navigator {
|
106 | 125 | [SecureContext] Promise<undefined> share(optional ShareData data = {});
|
| 126 | + |
| 127 | + [SecureContext] boolean canShare(optional ShareData data = {}); |
107 | 128 | };
|
108 | 129 | </pre>
|
109 | 130 | <p>
|
@@ -257,6 +278,25 @@ <h4>
|
257 | 278 | or bypassing the UI if there is only a single share target.
|
258 | 279 | </div>
|
259 | 280 | </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 use</a> |
| 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> |
260 | 300 | <section>
|
261 | 301 | <h3>
|
262 | 302 | Validate share data
|
|
0 commit comments