Skip to content

Commit

Permalink
trying fix share-target not included in build
Browse files Browse the repository at this point in the history
  • Loading branch information
Brunwo committed Oct 7, 2024
1 parent b0c0118 commit dc1a459
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}
],
"share_target": {
"action": "share-target/",
"action": "share-target",
"method": "GET",
"params": {
"title": "title",
Expand Down
12 changes: 12 additions & 0 deletions public/share-target.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Handling Share...</title>
</head>
<body>
<p>Handling shared content...</p>
<script src="share-target.js"></script>
</body>
</html>
16 changes: 16 additions & 0 deletions public/share-target.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This function will be called when the PWA receives a share
function handleShareTarget() {
const urlParams = new URLSearchParams(window.location.search);
const sharedUrl = urlParams.get('url') || urlParams.get('text');

if (sharedUrl) {
// Redirect to the main page with the shared URL as a parameter
window.location.href = `index.html?url=${encodeURIComponent(sharedUrl)}`;
} else {
// If no URL is shared, just go to the main page
window.location.href = 'index.html';
}
}

// Call the function when the page loads
handleShareTarget();

0 comments on commit dc1a459

Please sign in to comment.