Skip to content

Commit

Permalink
Basic test case for same-origin Web Install
Browse files Browse the repository at this point in the history
  • Loading branch information
amandabaker committed Jul 19, 2024
1 parent 8e46aed commit ba42f52
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 0 deletions.
Binary file added web_install/144x144.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web_install/48x48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions web_install/app.js
Original file line number Diff line number Diff line change
@@ -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);
37 changes: 37 additions & 0 deletions web_install/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>Web Install Sample</title>
<link rel="manifest" href="./manifest.webmanifest" />
</head>
<body>
<h1>Web Install Sample</h1>
<p>
A debugging tool for the Web Install API. See more info in the
<a
href="https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/main/WebInstall/explainer.md"
>explainer</a
>
and to-do's in this
<a href="https://github.com/amandabaker/pwa/issues/22">GitHub issue</a>.
</p>

<h2>Install same-origin with preset id</h2>
<p>Executes:</p>
<pre><code>
let manifest_id = "https://amandabaker.github.io/pwa/web_install.html";
let install_url = manifest_id;
navigator.install(manifest_id, install_url);
</code></pre>
<button id="installPreset">Install</button>

<!-- <h2>Install with custom info</h2>
<p>Executes <code>navigator.install(manifest_id, install_url)</code> using:</p>
<p><code>manifest_id = </code><input></p>
<p><code>install_url = </code><input></p>
<button id="installCustom">Install</button> -->
</body>
<script src="app.js"></script>
</html>
16 changes: 16 additions & 0 deletions web_install/manifest.webmanifest
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
12 changes: 12 additions & 0 deletions web_install/sw.js
Original file line number Diff line number Diff line change
@@ -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');
})
);
});

0 comments on commit ba42f52

Please sign in to comment.