Skip to content

Commit

Permalink
Format update for Web Share API (mdn#33037)
Browse files Browse the repository at this point in the history
* feat: update methods

* feat: format update

* update
  • Loading branch information
skyclouds2001 committed Apr 11, 2024
1 parent f6fd1d7 commit 91907f1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
18 changes: 11 additions & 7 deletions files/en-us/web/api/navigator/canshare/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ browser-compat: api.Navigator.canShare

{{APIRef("Web Share API")}}{{securecontext_header}}

The **`Navigator.canShare()`** method of the [Web Share API](/en-US/docs/Web/API/Web_Share_API) returns `true` if the equivalent call to {{domxref("navigator.share()")}} would succeed.
The **`canShare()`** method of the {{domxref("Navigator")}} interface returns `true` if the equivalent call to {{domxref("navigator.share()")}} would succeed.

The method returns `false` if the data cannot be _validated_. Reasons the data might be invalid include:

Expand All @@ -17,8 +17,8 @@ The method returns `false` if the data cannot be _validated_. Reasons the data m
- Files are specified but the implementation does not support file sharing.
- Sharing the specified data would be considered a "hostile share" by the user-agent.

The Web Share API is gated by the [web-share](/en-US/docs/Web/HTTP/Headers/Permissions-Policy/web-share) permission policy.
The **`canShare()`** method will return `false` if the permission is supported but has not been granted.
The [Web Share API](/en-US/docs/Web/API/Web_Share_API) is gated by the [web-share](/en-US/docs/Web/HTTP/Headers/Permissions-Policy/web-share) permission policy.
The `canShare()` method will return `false` if the permission is supported but has not been granted.

## Syntax

Expand All @@ -39,10 +39,14 @@ canShare(data)

Possible values are:

- `url`: A string representing a URL to be shared.
- `text`: A string representing text to be shared.
- `title`: A string representing the title to be shared.
- `files`: An array of {{domxref("File")}} objects representing files to be shared.
- `url` {{optional_inline}}
- : A string representing a URL to be shared.
- `text` {{optional_inline}}
- : A string representing text to be shared.
- `title` {{optional_inline}}
- : A string representing the title to be shared.
- `files` {{optional_inline}}
- : An array of {{domxref("File")}} objects representing files to be shared.

### Return value

Expand Down
19 changes: 13 additions & 6 deletions files/en-us/web/api/navigator/share/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ browser-compat: api.Navigator.share

{{APIRef("Web Share API")}}{{securecontext_header}}

The **`navigator.share()`** method of the [Web Share API](/en-US/docs/Web/API/Web_Share_API) invokes the native sharing mechanism of the device to share data such as text, URLs, or files. The available _share targets_ depend on the device, but might include the clipboard, contacts and email applications, websites, Bluetooth, etc.
The **`share()`** method of the {{domxref("Navigator")}} interface invokes the native sharing mechanism of the device to share data such as text, URLs, or files. The available _share targets_ depend on the device, but might include the clipboard, contacts and email applications, websites, Bluetooth, etc.

The method resolves a {{jsxref("Promise")}} with `undefined`.
On Windows this happens when the share popup is launched, while on Android the promise resolves once the data has successfully been passed to the _share target_.

The [Web Share API](/en-US/docs/Web/API/Web_Share_API) is gated by the [web-share](/en-US/docs/Web/HTTP/Headers/Permissions-Policy/web-share) permission policy.
The `share()` method will throw exceptions if the permission is supported but has not been granted.

## Syntax

```js-nolint
Expand All @@ -21,7 +24,7 @@ navigator.share(data)

### Parameters

- `data`
- `data` {{optional_inline}}

- : An object containing data to share.

Expand All @@ -30,10 +33,14 @@ navigator.share(data)

Possible values are:

- `url`: A string representing a URL to be shared.
- `text`: A string representing text to be shared.
- `title`: A string representing a title to be shared. May be ignored by the target.
- `files`: An array of {{domxref("File")}} objects representing files to be shared. See [below](#shareable_file_types) for shareable file types.
- `url` {{optional_inline}}
- : A string representing a URL to be shared.
- `text` {{optional_inline}}
- : A string representing text to be shared.
- `title` {{optional_inline}}
- : A string representing a title to be shared. May be ignored by the target.
- `files` {{optional_inline}}
- : An array of {{domxref("File")}} objects representing files to be shared. See [below](#shareable_file_types) for shareable file types.

### Return value

Expand Down
7 changes: 4 additions & 3 deletions files/en-us/web/api/web_share_api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ page-type: web-api-overview
browser-compat:
- api.Navigator.share
- api.Navigator.canShare
spec-urls: https://w3c.github.io/web-share/
---

{{DefaultAPISidebar("Web Share API")}}
{{DefaultAPISidebar("Web Share API")}}{{securecontext_header}}

The **Web Share API** provides a mechanism for sharing text, links, files, and other content to an arbitrary _share target_ selected by the user.

{{securecontext_header}}

> **Note:** This API is _not available_ in [Web Workers](/en-US/docs/Web/API/Web_Workers_API) (not exposed via {{domxref("WorkerNavigator")}}).
> **Note:** This API should not be confused with the [Web Share Target API](/en-US/docs/Web/Manifest/share_target), which allows a website to specify itself as a share target.
Expand All @@ -34,6 +33,8 @@ If the policy is supported but has not been granted, both methods will indicate

## Interfaces

### Extensions to other interfaces

- {{domxref("navigator.canShare()")}}
- : Returns a boolean indicating whether the specified data is shareable.
- {{domxref("navigator.share()")}}
Expand Down

0 comments on commit 91907f1

Please sign in to comment.