← Home ← Codex ← DEBT ← Engine
Browse by Category
+ added · updated 7d
← Back to glossary

Web Share API

JavaScript HTML5 Beginner
debt(d7/e3/b1/t7)
d7 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'only careful code review or runtime testing' (d7), because detection_hints.automated is 'no' and the pattern navigator.share is straightforward syntax, but the real mistakes (missing support checks, calling outside user gestures, no fallback) require runtime testing or manual review to catch reliably.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3), because quick_fix is 'Check navigator.share before calling. Always handle AbortError. Provide clipboard fallback' — this is a small, localised refactor within a single component (one share function/button) that doesn't require cross-file changes.

b1 Burden Structural debt — long-term weight of choosing wrong

Closest to 'minimal commitment' (b1), because the choice applies only to web contexts and only affects sharing functionality — it's a localised feature addition with no architectural weight or reach across the codebase; future maintainers pay no tax unless they modify the share button itself.

t7 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap' (t7), because the misconception 'navigator.share() works on all devices' directly contradicts developer intuition (a cross-platform API name suggests universal support), and the silent failure on desktop (no error, just unavailable) contradicts how similar browser APIs behave; the requirement to call only within a user gesture is also non-obvious and catches many developers.

About DEBT scoring →

TL;DR

navigator.share() invokes the native OS share sheet on mobile — letting users share URLs, text, and files via any app installed on their device.

Explanation

navigator.share({ title, text, url }) opens the native share dialog on supported platforms (Android, iOS, Windows 11). Returns a Promise that resolves when sharing completes or rejects if cancelled. Check support: navigator.canShare(data) before calling. Requires user gesture (click handler). Supports sharing files via navigator.share({ files: [...] }). Falls back gracefully on desktop where it may not be available. Progressive enhancement: show custom social share buttons when share API unavailable.

Common Misconception

navigator.share() works on all devices including desktop browsers — it's primarily a mobile API and may not be available on desktop Chrome/Firefox.

Why It Matters

Web Share API provides native sharing UX on mobile without requiring custom share buttons for every platform — one button, all apps.

Common Mistakes

  • Not checking navigator.share support before calling.
  • Calling share outside a user gesture (click/touch) — browsers reject it.
  • Not providing a fallback for browsers without support.

Code Examples

✗ Vulnerable
// No feature detection:
await navigator.share({ url: window.location.href });
✓ Fixed
async function shareContent(title, url) {
    if (navigator.share) {
        try {
            await navigator.share({ title, url });
        } catch (err) {
            if (err.name !== 'AbortError') throw err;
        }
    } else {
        // Fallback: copy link or show custom share UI
        await navigator.clipboard.writeText(url);
        showToast('Link copied!');
    }
}

Added 23 Mar 2026
Edited 5 Apr 2026
Views 95
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 1 ping F 3 pings S 0 pings S 3 pings M 1 ping T 0 pings W 0 pings T 0 pings F 2 pings S 1 ping S 1 ping M 1 ping T 3 pings W 0 pings T 1 ping F 0 pings S 3 pings S 3 pings M 0 pings T 1 ping W 0 pings T 1 ping F 0 pings S 0 pings S 0 pings M 2 pings T 1 ping W 0 pings T 1 ping F
Applebot 1
No pings yesterday
ChatGPT 21 Amazonbot 10 Google 8 Perplexity 7 Unknown AI 4 Ahrefs 4 Scrapy 4 Majestic 2 PetalBot 2 Twitter/X 2 Meta AI 1 Bing 1 Brave Search 1 Applebot 1
crawler 64 crawler_json 2 pre-tracking 2
🧱 FUNDAMENTALS — new to this? Start with the ground floor.
JavaScript javascript The programming language of the browser — it reads and modifies the page (the DOM), reacts to user events, and fetches data without reloading.

JavaScript is the only language browsers execute, so every interactive behaviour on the web goes through it. Its two defining traits — single-threaded event loop and loose typing (== coercion) — explain the majority of both its bugs and its design patterns.

💡 Default to const, use === always, and reach for let only when a value genuinely reassigns.

Ask Codex about JavaScript →
DEV INTEL Tools & Severity
🔵 Info ⚙ Fix effort: Low
⚡ Quick Fix
Check navigator.share before calling. Always handle AbortError (user cancelled). Provide clipboard fallback for unsupported browsers.
📦 Applies To
javascript HTML5 web
🔗 Prerequisites
🔍 Detection Hints
navigator.share
Auto-detectable: ✗ No
🤖 AI Agent
Confidence: Low False Positives: Medium ✗ Manual fix Fix: Low Context: Function


✓ schema.org compliant