From ba42f52eff1e761cc27681084689c06d653112b8 Mon Sep 17 00:00:00 2001 From: Amanda Baker Date: Fri, 19 Jul 2024 12:47:15 -0700 Subject: [PATCH] Basic test case for same-origin Web Install --- web_install/144x144.png | Bin 0 -> 484 bytes web_install/48x48.png | Bin 0 -> 193 bytes web_install/app.js | 26 ++++++++++++++++++++++ web_install/index.html | 37 +++++++++++++++++++++++++++++++ web_install/manifest.webmanifest | 16 +++++++++++++ web_install/sw.js | 12 ++++++++++ 6 files changed, 91 insertions(+) create mode 100644 web_install/144x144.png create mode 100644 web_install/48x48.png create mode 100644 web_install/app.js create mode 100644 web_install/index.html create mode 100644 web_install/manifest.webmanifest create mode 100644 web_install/sw.js diff --git a/web_install/144x144.png b/web_install/144x144.png new file mode 100644 index 0000000000000000000000000000000000000000..32e09558eaa8dc01565f1fbd61bbde1ed703fb09 GIT binary patch literal 484 zcmeAS@N?(olHy`uVBq!ia0vp^6F``Q4M;wBd$a>cF%}28J29*~C-V}>VM%xNb!1@J z*w6hZkrl}2EbxddW?&Fg1z|?dAe9e54V9iQjv*CsZ!Z}#9#9ZCa3KHhY6n@pTdb@p zd!v&S&ae5)8&l=~u&dF7$0bQYhLW0HE{^l&^l}_?3`oNfB N@O1TaS?83{1ORtDf>Zzi literal 0 HcmV?d00001 diff --git a/web_install/48x48.png b/web_install/48x48.png new file mode 100644 index 0000000000000000000000000000000000000000..aa7d86876dc3bbc4ddde816ab575d9a8b09d58ce GIT binary patch literal 193 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpTC#^NA%Cx&(BWL^R}Ea{HEjtmSN z`?>!lvI6;>1s;*b3=CqbAk63)r1AkM80P8X7?R=q_PinQ0Rw>p2mF67*4VYlV|syw t>nGiLd!PON7W2k(Zy0kF3Gmt({uRrZUUscd&;Z)N;OXk;vd$@?2>>S5H2eSn literal 0 HcmV?d00001 diff --git a/web_install/app.js b/web_install/app.js new file mode 100644 index 0000000..627c902 --- /dev/null +++ b/web_install/app.js @@ -0,0 +1,26 @@ +const registerServiceWorker = async () => { + try { + await navigator.serviceWorker.register("./sw.js"); + console.log("Service worker registered"); + } catch (e) { + console.log(`Registration failed: ${e}`); + } +}; + +if (navigator.serviceWorker) { + registerServiceWorker(); +} + +// Handle install buttons. +const installPreset = (e) => { + // Make sure to update the visible code sample in index.html when updating + // this. + let manifest_id = "https://amandabaker.github.io/pwa/web_install.html"; + let install_url = manifest_id; + navigator.install(manifest_id, install_url); +}; + +// const installCustom = (e) => {} + +document.getElementById("installPreset").addEventListener("click", installPreset); +// document.getElementById("installCustom").addEventListener("click", installCustom); diff --git a/web_install/index.html b/web_install/index.html new file mode 100644 index 0000000..4008dca --- /dev/null +++ b/web_install/index.html @@ -0,0 +1,37 @@ + + + + + + Web Install Sample + + + +

Web Install Sample

+

+ A debugging tool for the Web Install API. See more info in the + explainer + and to-do's in this + GitHub issue. +

+ +

Install same-origin with preset id

+

Executes:

+

+      let manifest_id = "https://amandabaker.github.io/pwa/web_install.html";
+      let install_url = manifest_id;
+      navigator.install(manifest_id, install_url);
+    
+ + + + + + diff --git a/web_install/manifest.webmanifest b/web_install/manifest.webmanifest new file mode 100644 index 0000000..8689161 --- /dev/null +++ b/web_install/manifest.webmanifest @@ -0,0 +1,16 @@ +{ + "name": "Web Install Sample", + "display": "standalone", + "start_url": "./index.html", + "theme_color": "#296f78", + "icons": [ + { + "src": "48x48.png", + "sizes": "48x48" + }, + { + "src": "144x144.png", + "sizes": "144x144" + } + ] +} \ No newline at end of file diff --git a/web_install/sw.js b/web_install/sw.js new file mode 100644 index 0000000..fb76383 --- /dev/null +++ b/web_install/sw.js @@ -0,0 +1,12 @@ + +this.addEventListener('install', async (event) => { + return; +}); + +self.addEventListener('fetch', e => { + e.respondWith( + fetch(e.request).catch(() => { + return new Response('Hello offline page'); + }) + ); +});