Navigator: canShare() method

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

The canShare() method of the Navigator interface returns true if the equivalent call to navigator.share() would succeed.

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

  • The data parameter has been omitted or only contains properties with unknown values. Note that any properties that are not recognized by the user agent are ignored.
  • A URL is badly formatted.
  • 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 permission policy. The canShare() method will return false if the permission is supported but has not been granted.

Syntax

js
canShare()
canShare(data)

Parameters

data Optional

An object defining the share data to test. Typically, an object with the same properties is passed to navigator.share() if this call returns true.

Properties that are unknown to the user agent are ignored; share data is only assessed on properties understood by the user agent. All properties are optional but at least one known data property must be specified or the method will return false.

Possible values are:

url Optional

A string representing a URL to be shared.

text Optional

A string representing text to be shared.

title Optional

A string representing the title to be shared.

files Optional

An array of File objects representing files to be shared.

Return value

Returns true if the specified data can be shared with Navigator.share(), otherwise false.

Examples

Sending the MDN URL

The example uses navigator.canShare() to check whether navigator.share() can share the specified data.

HTML

The HTML just creates a paragraph in which to display the result of the test.

html
<p class="result"></p>

JavaScript

js
let shareData = {
  title: "MDN",
  text: "Learn web development on MDN!",
  url: "https://developer.mozilla.org",
};

const resultPara = document.querySelector(".result");

if (!navigator.canShare) {
  resultPara.textContent = "navigator.canShare() not supported.";
} else if (navigator.canShare(shareData)) {
  resultPara.textContent =
    "navigator.canShare() supported. We can use navigator.share() to send the data.";
} else {
  resultPara.textContent = "Specified data cannot be shared.";
}

Result

The box below should state whether navigator.canShare() is supported on this browser, and if so, whether or not we can use navigator.share() to share the specified data:

Feature checking example

This method feature tests whether a particular data property is valid and shareable. If used with a single data property it will return true only if that property is valid and can be shared on the platform.

The code below demonstrates verifying that a data property is supported.

js
// Feature that may not be supported
let testShare = { someNewProperty: "Data to share" };

// Complex data that uses new key
const shareData = {
  title: "MDN",
  text: "Learn web development on MDN!",
  url: "https://developer.mozilla.org",
  someNewProperty: "Data to share",
};

// Test that the key is valid and supported before sharing
if (navigator.canShare(testShare)) {
  // Use navigator.share() to share 'shareData'
} else {
  // Handle case that new data property can't be shared.
}

Specifications

Specification
Web Share API
# canshare-data-method

Browser compatibility

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Node.js
canShare
Chrome – Partial support
Chrome 89 – 127 (Release date: 2021-03-02)
footnote Partial support
footnote Only supported on ChromeOS and Windows, see bug 40542648 and bug 40729163.
Chrome – Full support
Chrome 128 (Release date: 2024-08-20)
footnote Full support
Edge – Partial support
Edge 81 – 92 (Release date: 2020-04-13)
footnote Partial support
footnote Only supported on Windows.
Edge – Full support
Edge 93 (Release date: 2021-09-02)
footnote Full support
Firefox – No support
Firefox 96 (Release date: 2022-01-11)
disabled
disabled From version 96 users must explicitly set the dom.webshare.enabled preference to true. To change preferences in Firefox, visit about:config.
Opera – Partial support
Opera 75 – 113 (Release date: 2021-03-24)
footnote Partial support
footnote Only supported on ChromeOS and Windows, see bug 40542648 and bug 40729163.
Opera – Full support
Opera 114 (Release date: 2024-09-25)
footnote Full support
Safari – Full support
Safari 14 (Release date: 2020-09-16)
footnote Full support
Chrome Android – Full support
Chrome Android 75 (Release date: 2019-06-04)
footnote Full support
Firefox for Android – Full support
Firefox for Android 96 (Release date: 2022-01-11)
footnote Full support
Opera Android – Full support
Opera Android 54 (Release date: 2019-10-18)
footnote Full support
Safari on iOS – Full support
Safari on iOS 14 (Release date: 2020-09-16)
footnote Full support
Samsung Internet – Full support
Samsung Internet 11 (Release date: 2019-12-05)
footnote Full support
WebView Android – No support
WebView Android
footnote
footnote See bug 40540400
WebView on iOS – Full support
WebView on iOS 14 (Release date: 2020-09-16)
footnote Full support
Node.js – No support
Node.js
footnote No support
data.files parameter
Chrome – Full support
Chrome 89 (Release date: 2021-03-02)
footnote Full support
Edge – Full support
Edge 81 (Release date: 2020-04-13)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 75 (Release date: 2021-03-24)
footnote Full support
Safari – Full support
Safari 14 (Release date: 2020-09-16)
footnote Full support
Chrome Android – Full support
Chrome Android 76 (Release date: 2019-07-30)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 54 (Release date: 2019-10-18)
footnote Full support
Safari on iOS – Full support
Safari on iOS 14 (Release date: 2020-09-16)
footnote Full support
Samsung Internet – Full support
Samsung Internet 11 (Release date: 2019-12-05)
footnote Full support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – Full support
WebView on iOS 14 (Release date: 2020-09-16)
footnote Full support
Node.js – No support
Node.js
footnote No support
data.text parameter
Chrome – Full support
Chrome 89 (Release date: 2021-03-02)
footnote Full support
Edge – Full support
Edge 81 (Release date: 2020-04-13)
footnote Full support
Firefox – No support
Firefox 96 (Release date: 2022-01-11)
disabled
disabled From version 96 users must explicitly set the dom.webshare.enabled preference to true. To change preferences in Firefox, visit about:config.
Opera – Full support
Opera 75 (Release date: 2021-03-24)
footnote Full support
Safari – Full support
Safari 14 (Release date: 2020-09-16)
footnote Full support
Chrome Android – Full support
Chrome Android 76 (Release date: 2019-07-30)
footnote Full support
Firefox for Android – Full support
Firefox for Android 96 (Release date: 2022-01-11)
footnote Full support
Opera Android – Full support
Opera Android 54 (Release date: 2019-10-18)
footnote Full support
Safari on iOS – Full support
Safari on iOS 14 (Release date: 2020-09-16)
footnote Full support
Samsung Internet – Full support
Samsung Internet 11 (Release date: 2019-12-05)
footnote Full support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – Full support
WebView on iOS 14 (Release date: 2020-09-16)
footnote Full support
Node.js – No support
Node.js
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support
See implementation notes.
User must explicitly enable this feature.
Has more compatibility info.

See also