JavaScript Navigator canShare() Method

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs

What You’ll Learn

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()

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).

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.

📝 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
}

⚡ Quick Reference

GoalCode
Feature detecttypeof navigator.canShare === "function"
Validate share payloadnavigator.canShare(shareData)
Test URL onlynavigator.canShare({ url })
Test files onlynavigator.canShare({ files })
Open share UIawait navigator.share(shareData)
Secure context?window.isSecureContext

🔍 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

📋 canShare() vs share()

canShare()share()
Shows UI?NoYes (native share sheet)
Return typebooleanPromise
PurposeValidate data / platform supportPerform the share
User gestureNot requiredUsually required (transient activation)
When to callBefore enabling Share / before share()On Share button click

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.

Example 1 — Feature Detection

Check whether canShare exists before calling it.

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

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.");
}
Try It Yourself

How It Works

Pass the same object shape you plan to send to share().

📈 Practical Patterns

Probe single properties, file sharing, and a safe Share button.

Example 3 — Feature-Check One Property

MDN pattern: test whether a single data key is valid on this platform.

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

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);
Try It Yourself

How It Works

Always test files with canShare({ files }) — support differs by OS and file type.

Example 5 — Enable Share Only When Valid

Beginner UI helper: enable a Share control only when the payload is shareable.

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

Keep a copy-to-clipboard fallback when the Share button stays disabled.

🚀 Common Use Cases

  • Share article links — validate title / text / URL before opening the sheet.
  • Share generated files — check { files } before offering download-or-share.
  • Progressive Share buttons — show Share only when canShare returns true.
  • Platform capability probes — test one property at a time for feature support.
  • Safer UX — avoid calling share() with data that will fail validation.

🧠 How navigator.canShare() Works

1

Detect the method

Confirm navigator.canShare exists on a secure page.

Detect
2

Build share data

Provide known fields: url, text, title, and/or files.

Data
3

Call canShare(data)

Get a boolean without opening the share UI.

Validate
4

Call share() on click

If true, open the native sheet from a user gesture; else use a fallback.

📝 Notes

  • Limited availability (not Baseline) — feature-detect always.
  • Not Deprecated, Experimental, or Non-standard — no status banner required (MDN/BCD).
  • Secure context required (HTTPS / localhost).
  • Returns a boolean; pair with navigator.share() for the actual share UI.
  • Related: clearAppBadge(), clipboard, userActivation, Window.

Limited Availability Support

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?

Limited Not Baseline
Google Chrome canShare · desktop/mobile (version varies)
Limited
Microsoft Edge canShare · follow Chromium / Windows notes
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.

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.

Continue with clearAppBadge(), clipboard, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Feature-detect navigator.canShare
  • Validate the same data you will pass to share()
  • Use HTTPS / localhost
  • Test files with canShare({ files })
  • Provide a copy-link fallback

❌ Don’t

  • Assume Baseline support everywhere
  • Call share() without validating risky payloads
  • Rely on unknown custom properties alone
  • Ignore secure-context requirements
  • Expect canShare() to open the share sheet

Key Takeaways

Knowledge Unlocked

Five things to remember about canShare()

Validate share data first — then call share() from a click.

5
Core concepts
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.

Explore clearAppBadge() Next

Remove app icon badges when unread counts hit zero.

clearAppBadge() →

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.

8 people found this page helpful