On this page
A PWA share target can turn an incoming shared link into a navigation to your app. Before releasing, test both parts of that path: the destination URL your app parses and the installed app’s behavior when a real browser and operating system deliver a share.
This guide uses a GET share target and a small diagnostic page to exercise encoded values, missing fields, repeated parameters, and an action outside the intended app scope.
Verification limitation: The current W3C specification and browser documentation were not available for review here, and the examples were not executed. Check the specification and documentation for your target browser versions before publishing or relying on their behavior. In particular, support and share-sheet registration must be verified on actual target devices.
Key Takeaways
- A manifest maps incoming
title,text, andurlvalues to names in the action URL’s query string. The action itself is a URL, not a placeholder-based template. - Use
URLSearchParamsto decode and inspect values; usegetAll()when testing repeated parameters. - A manually constructed destination tests your page’s parsing, not whether the PWA appears in a share sheet.
- Keep the action inside the intended app scope and test it on each supported browser and device.
- Treat shared values as untrusted input, especially before rendering, navigating to, or fetching a shared URL.
Configure a GET share target
The following is a partial manifest, intended to be added to an existing PWA manifest. It assumes the app is served from the same origin under /app/ and that the server serves the diagnostic page at /app/share-target/. Your existing manifest and deployment must also satisfy the installation requirements of the browsers you support.
{
"name": "Share Test App",
"short_name": "Share Test",
"start_url": "/app/",
"scope": "/app/",
"share_target": {
"action": "/app/share-target/",
"method": "GET",
"enctype": "application/x-www-form-urlencoded",
"params": {
"title": "shared_title",
"text": "shared_text",
"url": "shared_url"
}
}
}
The keys title, text, and url identify the kinds of incoming share data. Their values name the query parameters the receiving page reads. A conceptual destination has the shape /app/share-target/?shared_title=...&shared_text=...&shared_url=...; the ellipses represent encoded values, not literal manifest placeholders. A share need not provide all three fields.
For this diagnostic, use an action without an existing query string. That makes it easier to distinguish parameters added for the share from parameters already present in the action.
Advertisement
Inspect the incoming parameters
Serve the following page at /app/share-target/, or adapt the script to your existing route. It displays the decoded values without inserting them as HTML. The page is a diagnostic, not a complete share-processing application.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Share target diagnostic</title>
</head>
<body>
<h1>Incoming share</h1>
<pre id="result"></pre>
<script>
const params = new URLSearchParams(window.location.search);
const fields = ["shared_title", "shared_text", "shared_url"];
const result = {};
for (const field of fields) {
result[field] = params.getAll(field);
}
document.getElementById("result").textContent =
JSON.stringify(result, null, 2);
</script>
</body>
</html>
An absent parameter produces an empty array in this diagnostic; a present parameter with an empty value produces an array containing an empty string. Repeated parameters produce multiple array entries. If your application expects only one value per field, define whether to reject duplicates or choose one deliberately rather than silently assuming duplicates cannot occur.
URLSearchParams decodes query-string encoding. In form-style query strings, a literal plus sign must be encoded as %2B; an unescaped + is interpreted as a space. Don’t decode the returned value again: a second decoding step can change the data or fail on a literal percent sign.
Test destination URLs locally
First open the installed app’s origin in a browser where your diagnostic route is served. In its developer console, construct and navigate to a destination:
const destination = new URL("/app/share-target/", window.location.origin);
destination.searchParams.set("shared_title", "Café + tea");
destination.searchParams.set("shared_text", "A & B = 100%");
destination.searchParams.set("shared_url", "https://example.test/item?q=a%2Bb&lang=en");
window.location.assign(destination.href);
The nested shared URL is fictional. Its own query string is data inside the outer shared_url parameter. Check that the diagnostic displays the original title, text, and URL as separate values, including the plus sign, ampersands, and percent sign. This checks your route and parsing, not the operating system’s share flow.
Next, use the address bar or console to try these cases:
- Missing fields: Navigate to
/app/share-target/?shared_url=https%3A%2F%2Fexample.test%2F. Confirm the title and text arrays are empty and the URL remains available. - Empty versus missing: Navigate to
/app/share-target/?shared_title=&shared_text=hello. Confirm the title is present but empty, while the URL is absent. - Repeated parameters: Navigate to
/app/share-target/?shared_text=first&shared_text=second. Confirm both values are visible, then test your application’s chosen duplicate-handling policy. - Encoded characters: Repeat the console example with non-ASCII characters, spaces,
+,&, and%in each relevant field. Construct the query withURLSearchParamsrather than concatenating raw values.
Repeated parameters are a robustness test of the receiving route; constructing them manually does not establish that a particular browser will generate duplicates during a share.
Advertisement
Test the real share flow and scope
On each browser and device in your release matrix:
- Deploy the manifest and diagnostic route over HTTPS. Ensure the server returns the page for the action path, including when a query string is present. If a service worker handles navigations, check that its routing does not hide or mishandle this path.
- Install or reinstall the PWA as appropriate for the target browser after changing its manifest. Check that the installed app is registered as a share destination; exact installation and refresh behavior is browser-dependent.
- From an app or page that can share a link, open the operating system’s share sheet and select the PWA if it appears. Inspect which fields actually arrived. The sharing source may supply text, a URL, both, or other combinations.
- Repeat with a link containing its own query string and encoded characters. Compare what the source shared with what the diagnostic displays. Also try a share without a title or without a URL, if the source allows it.
- Record the device, operating system, browser version, installation state, source app, and result. If the PWA is absent from the share sheet, investigate browser support and registration before debugging query parsing.
Check an action outside the intended scope
In an isolated test build, change the action to /outside/share-target/ while keeping the manifest scope at /app/. Provide a test page at that outside path, then repeat installation or manifest-refresh steps and the real share attempt.
Record whether the target is registered and, if selected, whether the destination opens in the installed app or elsewhere. Do not assume the result is portable: verify the applicable specification constraints and the behavior of each browser version you support. Restore the in-scope action before release. A manually opened outside URL only tests navigation; it does not establish share-target registration or launch behavior.
Common Mistakes
- Putting placeholders in
action: Configure the parameter names underparams; do not assume{title}or similar text in the action will be substituted. - Testing only a copied URL: Direct navigation can validate parsing even when the browser never registers the PWA as a share target.
- Assuming every field exists: A shared link may arrive in text, URL, or a combination. Handle absent and empty fields separately.
- Splitting the query string by hand: Encoded delimiters and nested URLs make manual splitting error-prone.
- Treating an online parser as a compatibility test: Inspecting a generated destination can help debug its components, but it cannot verify browser support or share-sheet registration.
Best Practices
Render shared text as text, not HTML. If the app turns a shared URL into a link or navigation, parse it and explicitly allow only the schemes your feature needs; parsing alone does not establish that a destination is safe. Do not automatically fetch a shared URL from a server without separate SSRF defenses, including destination and redirect validation and network restrictions.
GET parameters can be exposed through browser history, logs, and other URL handling. Avoid putting sensitive shared content into a GET-based workflow without considering those exposures. Provide a clear error or fallback when the action route is unavailable or incoming data is unusable.
Conclusion
Test the destination parser with controlled edge cases, then test an actual share into the installed PWA on every supported platform. The first catches parsing bugs; the second checks the browser and operating system integration that a copied URL cannot prove.
What would your domain sell for?
A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.