Test the method.typeof … === "function" avoids calling a missing API.
Check share too. Detecting canShare usually implies share exists (MDN), but logging both is clear for beginners.
Confirm HTTPS.isSecureContext should be true on real deployments.
Plan a fallback. If either API is missing, offer copy-link instead of a Share button.
Example 2 — Validate Link Share Data
MDN’s basic pattern: test title, text, and url together.
JavaScript
const shareData = {
title: "MDN",
text: "Learn web development on MDN!",
url: "https://developer.mozilla.org"
};
if (!navigator.canShare) {
console.log("navigator.canShare() not supported.");
} else if (navigator.canShare(shareData)) {
console.log("We can use navigator.share() to send the data.");
} else {
console.log("Specified data cannot be shared.");
}
url: canShare missing
text: canShare missing
unknown: canShare missing
(or shareable / not shareable per key when supported)
How It Works
Isolate each field. Pass one known property so the result maps to that key.
Expect url/text to work on most supporting platforms when the values are valid.
Unknown keys are ignored. Alone, they leave no known data → usually false.
Use this before new fields. Probe experimental keys before bundling them into a full share.
Example 4 — Check File Sharing Support
Always test { files } before offering a file share action (MDN).
JavaScript
async function checkFileShareSupport() {
if (!navigator.canShare) {
return "Your browser doesn't support the Web Share API.";
}
const files = [
new File(["hello"], "hello.txt", { type: "text/plain" })
];
if (navigator.canShare({ files })) {
return "This system can share these files.";
}
return "Your system doesn't support sharing these files.";
}
checkFileShareSupport().then(console.log);
Share button enabled: false
(or true when canShare accepts the payload)
How It Works
Combine detect + validate. One helper keeps the button logic short.
Run at load (or when data changes). Set disabled from the boolean result.
Share only on click.share() needs a user gesture — never call it from idle script.
Keep a fallback. When enabled is false, offer copy-to-clipboard instead.
Compatibility
Browser Support
navigator.canShare() is part of the Web Share API and is not Baseline. Strong on many mobile browsers and modern Chromium / Safari; desktop Firefox is often disabled by default. Always feature-detect and use HTTPS.
✓ Limited availability · Not Baseline
Navigator.canShare()
Boolean check — would navigator.share(data) succeed with this payload?
LimitedNot Baseline
Google ChromecanShare from ~89+ (platform-dependent)
Limited
Microsoft EdgeFollow Chromium Web Share support
Limited
Apple SafaricanShare from Safari 14+
Supported
OperaFollow Chromium Web Share support
Limited
Mozilla FirefoxOften flag-gated on desktop — feature-detect
Limited
Internet ExplorerNo Web Share / canShare support
Unavailable
canShare()Limited
Bottom line: Detect canShare, validate your ShareData (especially files), call share() only from a click, and keep a copy-link fallback.
Frequently Asked Questions
It returns true if an equivalent call to navigator.share() with the same data would succeed, and false if the data cannot be validated or shared on this platform. It does not open the share sheet.
No. MDN does not mark it Deprecated, Experimental, or Non-standard. It is Limited availability (not Baseline) and requires a secure context. Always feature-detect.
Yes. The Web Share API is a secure-context feature (HTTPS or localhost) in supporting browsers.
An optional object with url, text, title, and/or files (File objects). Unknown properties are ignored. At least one known property must be present or the method returns false.
canShare() is a synchronous boolean check with no UI. share() opens the native share sheet and returns a Promise. Validate with canShare, then call share from a user gesture.
Common reasons: the method is missing, no valid known properties, a bad URL, files the platform cannot share, a hostile share blocked by the user agent, or the web-share permission policy is not granted.