Sharing from your app: Web Share API
shareButton.addEventListener('click', async () => {
const data = { title: document.title, text: 'Worth reading', url: location.href };
if (navigator.share && (!navigator.canShare || navigator.canShare(data))) {
try { await navigator.share(data); } catch (e) { /* user cancelled */ }
} else {
await navigator.clipboard.writeText(location.href); // fallback
}
});
Share files too: navigator.share({ files: [file], title: 'Photo' }), after checking navigator.canShare({ files: [file] }). It must be called from a user gesture. Supported in Safari (iOS and macOS), Chrome and Edge on Android, Windows and ChromeOS (and newer versions on macOS), Samsung Internet and Firefox for Android.
Receiving shares: Web Share Target
Add a share_target to your manifest, and your installed app appears in the system share sheet:
"share_target": {
"action": "/share",
"method": "GET",
"params": { "title": "title", "text": "text", "url": "url" }
}
The app opens /share?title=...&text=...&url=.... Note that some apps put the link in text rather than url, so check both.
To receive files, use POST with multipart/form-data and handle the request in your service worker:
"share_target": {
"action": "/share-image", "method": "POST", "enctype": "multipart/form-data",
"params": { "files": [{ "name": "image", "accept": ["image/*"] }] }
}
Share Target works in Chromium on Android and ChromeOS (and Edge on Windows). It is not supported on iOS.
PWA.live has a share target: install it on Android and share any link to PWA.live to open the PWA checker with that URL.
Browser support
| Feature | Chrome / Edge desktop | Chrome Android | Safari iOS / iPadOS | Safari macOS | Firefox desktop | Firefox Android | Samsung Internet |
|---|---|---|---|---|---|---|---|
| Web Share (share from your app) | Chrome / Edge desktop: Partial (Windows, ChromeOS and newer macOS versions) | Chrome Android: Yes | Safari iOS / iPadOS: Yes | Safari macOS: Yes | Firefox desktop: No | Firefox Android: Yes | Samsung Internet: Yes |
| Share target (receive shares) | Chrome / Edge desktop: Partial (ChromeOS, and Edge on Windows) | Chrome Android: Yes | Safari iOS / iPadOS: No | Safari macOS: No | Firefox desktop: No | Firefox Android: No | Samsung Internet: Yes |