navigator.canShare() is part of the Web Share API. Learn how to validate share data before calling navigator.share(), feature-detect support, test title / text / url / files, and use five examples with try-it labs.
01
Kind
Method
02
Returns
boolean
03
Status
Limited availability
04
Context
Secure (HTTPS)
05
API family
Web Share API
06
Pairs with
navigator.share()
Fundamentals
Introduction
Mobile and desktop browsers can open a native share sheet so users send a link, text, or files to another app. That UI comes from navigator.share().
Before you open that sheet — especially for files — ask: Would this share succeed?navigator.canShare(data) answers with a simple true or false, without showing any UI.
💡
Check first, share second
MDN pattern: feature-detect navigator.canShare, validate the data, then call navigator.share() from a button click (user gesture).
Concept
Understanding the canShare() Method
Think of canShare() as a dry run for share(). It checks whether the data is valid and shareable on this browser / OS.
Returns true — an equivalent share(data) call should succeed (data-wise).
Returns false — data omitted / unknown only, bad URL, unsupported files, hostile share, or missing permission.
Unknown properties — ignored by the user agent; only known keys count.
At least one known property — required, or the method returns false.
Secure context — HTTPS / localhost.
Permission policy — gated by web-share; may return false if not granted.
Foundation
📝 Syntax
General form of the method:
JavaScript
navigator.canShare()
navigator.canShare(data)
Parameters
data (optional) — object with any of: url, text, title, files.
Return value
true if the data can be shared with navigator.share(); otherwise false.
Common patterns
JavaScript
// MDN: validate share data before sharing
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.");
}
// Feature-test a single property (MDN)
const testShare = { someNewProperty: "Data to share" };
if (navigator.canShare && navigator.canShare(testShare)) {
// Property is valid on this platform
} else {
// Handle unsupported property
}
Cheat Sheet
⚡ Quick Reference
Goal
Code
Feature detect
typeof navigator.canShare === "function"
Validate share payload
navigator.canShare(shareData)
Test URL only
navigator.canShare({ url })
Test files only
navigator.canShare({ files })
Open share UI
await navigator.share(shareData)
Secure context?
window.isSecureContext
Snapshot
🔍 At a Glance
Four facts to remember about navigator.canShare().
Returns
boolean
Shareable?
Availability
Limited
Not Baseline
Context
HTTPS
Secure required
Next step
share()
On user click
Compare
📋 canShare() vs share()
canShare()
share()
Shows UI?
No
Yes (native share sheet)
Return type
boolean
Promise
Purpose
Validate data / platform support
Perform the share
User gesture
Not required
Usually required (transient activation)
When to call
Before enabling Share / before share()
On Share button click
Hands-On
Examples Gallery
Examples follow MDN navigator.canShare() patterns. Prefer Try It Yourself — support varies by browser and OS, and desktop Firefox may need a preference flag.
📚 Getting Started
Detect the method and validate a classic link share payload.
If the method is missing, hide the Share button and offer copy-link fallback.
Example 2 — Validate MDN URL Data
MDN’s basic example: 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(
"navigator.canShare() supported. 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
Unknown keys alone usually fail validation because the agent ignores them and sees no known data.
Example 4 — Check File Sharing Support
MDN file pattern: validate { files } before offering a file share action.
JavaScript
async function checkFileShareSupport() {
if (!navigator.canShare) {
return "Your browser doesn't support the Web Share API.";
}
// Tiny in-memory file for the capability check
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);
navigator.canShare() is part of the Web Share API and is not Baseline. Support is strong on many mobile browsers and newer Chromium / Safari builds, but varies by OS and file type. Always feature-detect, use HTTPS, validate with canShare, then call share from a user gesture.
✓ Limited availability · Not Baseline
Navigator.canShare()
Boolean check — would navigator.share(data) succeed with this payload?
LimitedNot Baseline
Google ChromecanShare · desktop/mobile (version varies)
Limited
Microsoft EdgecanShare · follow Chromium / Windows notes
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.
Wrap Up
Conclusion
navigator.canShare() is the safe pre-check for the Web Share API. Detect it, validate your payload, enable Share only when the answer is true, and open navigator.share() from a real click — with a copy-link fallback ready.
Validate share data first — then call share() from a click.
5
Core concepts
🔗01
Returns
boolean
Value
⚡02
Availability
Limited
Not Baseline
🔒03
Context
secure HTTPS
Required
📄04
Data
url text title files
ShareData
🎯05
Then
navigator.share()
On click
❓ 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.
No. MDN/BCD mark it as standard-track and not Experimental or Deprecated. It is Limited availability (not Baseline), so always feature-detect. No Deprecated / Experimental / Non-standard status banner is required.
Yes. The Web Share API is a secure-context feature (HTTPS or localhost) in supporting browsers.
An optional ShareData-like 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. share() opens the native share UI and returns a Promise. Use canShare first to validate data (especially files), then call share from a user gesture.
Common reasons: the method is missing, no valid known properties, a bad URL, files that the platform cannot share, a "hostile share" blocked by the user agent, or the web-share permission policy is not granted.
Did you know?
Detecting navigator.canShare usually implies navigator.share is present too — MDN notes that feature-detecting canShare() also implies the same for share(). Still validate the specific payload before sharing files.