Share Target

The Web Share Target API allows your PWA to receive content shared from other applications, making it appear alongside native apps in the system's share menu. Users can share text, links, and files directly to your PWA.

Overview

Share Target enables:

  • Content reception: Receive shared content from other apps

  • Native integration: Appear in OS share sheet

  • File handling: Accept images, documents, and other files

  • Seamless UX: Process shared content within your PWA

How It Works

  1. User shares content: From another app, user clicks "Share"

  2. Your PWA appears: Listed in the share menu

  3. User selects PWA: Chooses your app as destination

  4. PWA opens: Your app receives the shared content

  5. Content processed: Handle the shared data in your application

Browser Support

circle-info

Good Support: Web Share Target is supported in Chrome, Edge, and Samsung Internet on Android. Limited support on Desktop and iOS.

Check support:

  • Chrome/Edge: Full support (Android, Desktop)

  • Safari: Limited support

  • Firefox: Not supported yet

Basic Configuration

Sharing Text and URLs

Simple configuration to receive text and links:

How it works: When content is shared, your PWA opens at /share?title=...&text=...&url=...

Sharing Files

Accept image files via POST:

Complete Configuration

Handle text, URLs, and multiple file types:

Configuration Parameters

action

Type: string or URL object Required: Yes

The URL endpoint that handles shared content.

method

Type: string Values: GET or POST Default: GET

HTTP method for sharing.

Use GET when:

  • Sharing only text/URLs (no files)

  • Content is read-only

  • No data mutation

Use POST when:

  • Sharing files

  • Creating new entries (bookmarks, posts)

  • Mutating application state

enctype

Type: string Values: application/x-www-form-urlencoded or multipart/form-data Default: application/x-www-form-urlencoded

Encoding type for POST requests. Use multipart/form-data when accepting files.

params

Type: object

Defines parameter names for shared content.

Text Parameters

File Parameters

Symfony Implementation

Controller for Text/URL Sharing (GET)

Controller for File Sharing (POST)

Complete Handler (Text + Files)

Common Use Cases

1. Social Media: Share Posts

Accept text and images for new posts:

2. Bookmarking App

Save shared URLs:

3. Note-Taking App

Capture shared text and links:

Accept multiple images:

5. Music Player

Share audio files:

Frontend Handling

Pre-fill Form with Shared Data

Handle Shared Files with JavaScript

File Type Handling

Accept Specific Image Formats

Accept Documents

Accept Videos

Multiple File Types

Testing Share Target

Manual Testing on Android

  1. Install your PWA on Android device

  2. Open another app (e.g., Chrome, Gallery)

  3. Find content to share (webpage, photo)

  4. Tap Share button

  5. Select your PWA from share sheet

  6. Verify content is received correctly

Testing in Chrome DevTools

Share Target can be tested using Chrome DevTools on desktop:

Programmatic Testing

Test your share endpoint directly:

Best Practices

1. Use HTTP 303 See Other for POST

Prevent double submissions:

2. Validate Shared Content

Always validate received data:

3. Handle Missing Parameters

Content might be incomplete:

4. Provide User Feedback

Show success/error messages:

5. Authenticate Users

Require authentication for sharing:

Or redirect to login:

Debugging

Check Manifest

Verify share_target in manifest:

Log Received Data

Debug what your app receives:

Test Endpoint Directly

Test without share sheet:

Limitations

Browser Support

  • Android: Full support in Chrome, Edge, Samsung Internet

  • iOS/Safari: Not supported yet

  • Desktop: Limited (must install PWA first)

  • Firefox: Not supported

Platform Restrictions

  • Requires PWA to be installed

  • Only works on supported platforms

  • File size limits apply

  • Some MIME types may not work on all devices

Security Considerations

Validate File Types

Limit File Size

Sanitize Input

Resources

  • MDN Web Share Target: https://developer.mozilla.org/en-US/docs/Web/Manifest/share_target

  • Web.dev Article: https://web.dev/web-share-target/

  • Chrome Developers: https://developer.chrome.com/docs/capabilities/web-apis/web-share-target

  • W3C Spec: https://w3c.github.io/web-share-target/

Last updated

Was this helpful?