Created
November 30, 2021 21:50
-
-
Save fabiwlf/bef517877326771dc3efb193f7389bb6 to your computer and use it in GitHub Desktop.
Make web.whatsapp.com and any other website with service worker but no manifest installable from browser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const makeManifest = async (manifest) => { | |
| manifest.description = document.head.children.description?.content; | |
| const icons = await Promise.all(Array.from(document.querySelectorAll(`link[rel$="icon"]`)).map((icon) => new Promise((resolve) => { | |
| const img = new Image() | |
| img.src = icon.href || icon.src; | |
| img.onload = resolve; | |
| img.onerror = () => resolve(null); | |
| }))); | |
| for (let iconLoadEvent of icons) { | |
| if (!iconLoadEvent) continue; | |
| let [icon] = iconLoadEvent.path; | |
| manifest.icons.push({ | |
| "src": icon.src, | |
| "sizes": icon.width + "x" + icon.height | |
| }) | |
| } | |
| console.log(manifest); | |
| const manifestURL = URL.createObjectURL(new Blob([JSON.stringify(manifest)], { type: 'application/manifest+json' })); | |
| document.head.innerHTML += `<link rel="manifest" href="${manifestURL}">`; | |
| } | |
| makeManifest({ | |
| "name": window.document.title || "PWA", | |
| "short_name": window.document.title || "PWA", | |
| "icons": [ | |
| ], | |
| "start_url": window.location.href, | |
| "display": "standalone", | |
| "scope": "/" //not required | |
| }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment