Skip to content

Receive shared content (share target)

Published Updated

The share_target manifest member lets an installed PWA receive content from other apps through the operating system’s share sheet. A shared photo arrives as a File that you can preview and import. The Web App Manifest declares the receiving URL; the browser sends a GET or POST to it as a form submission.

You need an installable PWA with a service worker (see Make it installable); the share sheet lists a web app only after the user has installed it, on every platform. One share_target is allowed per manifest, so route different kinds of shares on the landing page.

action (the receiving URL, inside the manifest scope) and params (the mapping from share fields to request parameter names) are required. method defaults to GET and enctype to application/x-www-form-urlencoded. Receiving files requires POST with multipart/form-data and a files array whose entries name the field and the accepted MIME types or extensions; list both forms, because operating systems differ in which they match.

{
"name": "Scrapbook",
"start_url": "/",
"display": "standalone",
"share_target": {
"action": "/share",
"method": "POST",
"enctype": "multipart/form-data",
"params": {
"title": "title",
"text": "text",
"url": "url",
"files": [{ "name": "media", "accept": ["image/*", ".png", ".jpg", "video/*"] }]
}
}
}

A text-only target can keep the GET default: the browser opens action with ?title=…&text=…&url=… and the page reads new URL(location).searchParams. GET is simpler to debug but leaks the shared text into history and server logs; POST keeps it in the request body and is the only way to receive files.

A page cannot read a POST body, so the service worker intercepts the request in fetch, reads formData(), stores the files, and answers with a 303 See Other redirect to a page that displays them. The redirect stops a refresh from re-submitting the share. The redirect target carries a marker (?shared=1) so the page knows to look in the cache.

sw.js
self.addEventListener('fetch', (event) => {
const url = new URL(event.request.url);
if (event.request.method !== 'POST' || url.pathname !== '/share') return;
event.respondWith(
(async () => {
const formData = await event.request.formData();
const files = formData.getAll('media');
const cache = await caches.open('shared-content');
await Promise.all(files.map((file, i) => cache.put(`/shared/${i}`, new Response(file))));
const text = formData.get('text') || formData.get('url') || '';
return Response.redirect(`/share/view?shared=1&text=${encodeURIComponent(text)}`, 303);
})(),
);
});

Validate what arrives as you would any form submission: other apps place content in unexpected parameters, and the body comes from software you do not control.

The redirected page checks the marker, reads the stored responses back as Blobs, shows them for confirmation, and then deletes them so a second share does not pick up the first share’s files. Opening /share/view directly, without the marker, renders the normal view.

function isSharedLaunch() {
return new URLSearchParams(location.search).has('shared');
}
async function takeSharedFiles() {
if (!('caches' in window)) return [];
const cache = await caches.open('shared-content');
const requests = await cache.keys();
const files = await Promise.all(requests.map((request) => cache.match(request).then((r) => r.blob())));
await Promise.all(requests.map((request) => cache.delete(request)));
return files;
}
if (isSharedLaunch()) {
takeSharedFiles().then(renderSharedFiles);
} else {
renderDefaultView();
}

Install the PWA from the browser’s Install entry, open any photo app, choose Share, and pick your app’s name from the system sheet. The redirect lands on /share/view with the previews rendered from the cached files. Share a URL from the browser as well to see the Android text fallback in action. The browsers that offer an installed web app in the share sheet are listed in the table:

  • Legend
  • Yes
  • Partial
  • Flag
  • No
  • Unknown
Browser / PlatformSupportVersionsConfidenceSourceNotes
Chrome (Desktop)#Yes89highsource—
Chrome (Android)#Yes76highsource—
Edge (Desktop)#Yes89highsource1
Firefox (Desktop)#No—highsource2
Firefox (Android)#No—highsource3
Safari (macOS)#No—highsource4
Safari (iOS)#No—highsource56
Samsung Internet#Yes12.0highsource7
WebView (Android)#No—highsource8
  1. Derived by browser-compat-data mirroring from Chrome.
  2. Implementation tracking: https://bugzil.la/1476515.
  3. The property parses, but has no effect.
  4. Implementation tracking: https://webkit.org/b/194593.
  5. Implementation tracking: https://webkit.org/b/194593.
  6. Derived by browser-compat-data mirroring from Safari.
  7. Derived by browser-compat-data mirroring from Chrome Android.
  8. No WebView Android support is recorded in browser-compat-data.

Source data: /compatibility/manifest-share-target.json · Global usage: 75 % (StatCounter 2026-09, CC BY-SA 4.0)

Source: spec · MDN · Last verified 2026-10-20 · Confidence: high (computed from sources)

← Back to the Guides overview.