JavaScript Navigator canShare() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Method

Definition

navigator.canShare(data) returns true if an equivalent call to navigator.share(data) would succeed (MDN). It is a dry-run check — no share UI opens.

Pass the required arguments shown below. Check return values and browser support before you rely on the result.

Syntax

Call navigator.canShare. Start with this line.

JavaScript
navigator.canShare(data?)
CallWhat it does
navigator.canShare(data?)Primary signature.
navigator.canShare(...)Call with the arguments your case needs.

Built into the browser. Call canShare(...) on a Navigator — no import required.

Library declarations
JavaScript
navigator.canShare(data?)

Parameters

ParameterDescription
dataOptional. Share payload to validate (omit → usually false)
url / text / titleOptional. Known string fields (*at least one known field needed)
filesOptional. File[] — test before offering file share

Return Value

Return ValueDescription
*boolean — no Promise, no UI

JavaScript Examples

Example 1 — Feature Detection

Check whether canShare and share exist before using them.

JavaScript
const lines = [
  "canShare: " + (typeof navigator.canShare === "function" ? "available" : "missing"),
  "share: " + (typeof navigator.share === "function" ? "available" : "missing"),
  "isSecureContext: " + window.isSecureContext
];
console.log(lines.join("\n"));
Try It Yourself

How It Works

  1. Test the method. typeof … === "function" avoids calling a missing API.
  2. Check share too. Detecting canShare usually implies share exists (MDN), but logging both is clear for beginners.
  3. Confirm HTTPS. isSecureContext should be true on real deployments.
  4. 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.");
}
Try It Yourself

How It Works

  1. Build the payload. Use the same object shape you will pass to share().
  2. Guard the call. If canShare is missing, stop early — do not call it.
  3. Validate. canShare(shareData) returns a boolean with no UI.
  4. Branch. true → safe to share later; false → fix data or use a fallback.

Example 3 — Probe One Property at a Time

MDN feature-check: test a single key to see if that field is shareable here.

JavaScript
function describeKey(label, data) {
  if (!navigator.canShare) return label + ": canShare missing";
  return label + ": " + (navigator.canShare(data) ? "shareable" : "not shareable");
}

console.log([
  describeKey("url", { url: "https://developer.mozilla.org" }),
  describeKey("text", { text: "Hello from CodeToFun" }),
  describeKey("unknown", { someNewProperty: "Data to share" })
].join("\n"));
Try It Yourself

How It Works

  1. Isolate each field. Pass one known property so the result maps to that key.
  2. Expect url/text to work on most supporting platforms when the values are valid.
  3. Unknown keys are ignored. Alone, they leave no known data → usually false.
  4. 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);
Try It Yourself

How It Works

  1. Feature-detect first. Missing canShare means no Web Share path for files.
  2. Build a tiny File. An in-memory File is enough for a capability check.
  3. Test files alone. canShare({ files }) answers whether this OS can share that type.
  4. Gate the UI. Only show “Share file” when the check returns true.

Example 5 — Enable Share Only When Valid

Enable a Share control only when the payload is shareable on this device.

JavaScript
const shareData = {
  title: "CodeToFun",
  text: "Learn JavaScript with clear tutorials",
  url: "https://www.codetofun.com"
};

function canOfferShare(data) {
  return typeof navigator.canShare === "function" && navigator.canShare(data);
}

const enabled = canOfferShare(shareData);
console.log("Share button enabled: " + enabled);

// On click (user gesture), in a real page:
// if (enabled) await navigator.share(shareData);
Try It Yourself

How It Works

  1. Combine detect + validate. One helper keeps the button logic short.
  2. Run at load (or when data changes). Set disabled from the boolean result.
  3. Share only on click. share() needs a user gesture — never call it from idle script.
  4. Keep a fallback. When enabled is false, offer copy-to-clipboard instead.

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?

Limited Not Baseline
Google Chrome canShare from ~89+ (platform-dependent)
Limited
Microsoft Edge Follow Chromium Web Share support
Limited
Apple Safari canShare from Safari 14+
Supported
Opera Follow Chromium Web Share support
Limited
Mozilla Firefox Often flag-gated on desktop — feature-detect
Limited
Internet Explorer No 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.

Next: clearAppBadge()

Learn how to clear the app icon badge when unread counts hit zero.

clearAppBadge() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful