Frontend development · Intermediate · 25 min
Make a site installable as a progressive web app
By Padding · Updated 18 Nov 2026
Node.js 26.13 · Playwright 1.65.1 · checked in Chromium 159 on node:26
You will turn a small static site into an installable web app with a manifest, home screen icons including a maskable one, a registered service worker and two scripts that prove the browser accepts it.
On this page
An installed web app gets its own icon on the home screen or in the dock, opens in its own window without the address bar, and shows up in the app switcher like anything from an app store. The site underneath does not change. What changes is that you give the browser three things it can check: a manifest that describes the app, icons it can put on a home screen, and a page served from a secure origin. A service worker is the fourth piece. Chrome no longer needs one to offer an install, but registering one now gives you a worker to build on when you make the app work offline in the next tutorial.
You will build Ridgeway Bus Times, a one-page timetable for a fictional town bus service, and make it installable. Timetables are a good fit: people check them standing at a stop, often on a low-end Android phone with prepaid data. Installing a web app fetches a small package built from the manifest and icons, far smaller than a typical store app, and updates arrive the next time the page loads.
You will not open a browser to check most of the work. A Node script fetches and validates the manifest and every icon, and a Playwright script loads the page in Chromium, reads the manifest the way the browser does and confirms the service worker is running. The last step is the one you do by hand: installing on a phone.
Step 1 · Create the site and serve it on localhost
Make a demo folder with the page, a stylesheet and a small Node server. The server matters more than it looks. Browsers only allow service workers, and only offer install, on a secure origin, and http://localhost counts as one. Opening index.html straight from disk (file://) does not.
mkdir -p ~/bus-times-pwa
cd ~/bus-times-pwa
cat > index.html <<'HTML'
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Ridgeway Bus Times</title>
<link rel="stylesheet" href="/style.css">
</head>
<body>
<main>
<h1>Ridgeway Bus Times</h1>
<p class="note">Route 4 · Market Square to Hillside · weekdays</p>
<table>
<thead><tr><th scope="col">Market Square</th><th scope="col">Clinic</th><th scope="col">Hillside</th></tr></thead>
<tbody>
<tr><td>06:40</td><td>06:52</td><td>07:05</td></tr>
<tr><td>07:20</td><td>07:32</td><td>07:45</td></tr>
<tr><td>08:00</td><td>08:14</td><td>08:28</td></tr>
<tr><td>12:30</td><td>12:42</td><td>12:55</td></tr>
<tr><td>17:10</td><td>17:24</td><td>17:38</td></tr>
</tbody>
</table>
</main>
</body>
</html>
HTML
cat > style.css <<'CSS'
body { margin: 0; font-family: system-ui, sans-serif; background: #ffffff; color: #1b1f24; }
main { max-width: 30rem; margin: 0 auto; padding: 1rem; }
h1 { font-size: 1.5rem; margin: 0 0 0.25rem; }
.note { color: #5a6270; margin: 0 0 1rem; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 0.5rem; border-bottom: 1px solid #d5d9df; }
CSS
cat > server.mjs <<'JS'
import { createServer } from 'node:http';
import { readFile } from 'node:fs/promises';
import { extname, join, normalize } from 'node:path';
const root = import.meta.dirname;
const types = {
'.html': 'text/html; charset=utf-8',
'.css': 'text/css; charset=utf-8',
'.js': 'text/javascript; charset=utf-8',
'.webmanifest': 'application/manifest+json',
'.png': 'image/png',
};
createServer(async (req, res) => {
const { pathname } = new URL(req.url, 'http://localhost');
const file = normalize(join(root, pathname === '/' ? 'index.html' : pathname));
const type = types[extname(file)];
if (!file.startsWith(root) || !type || file.includes('node_modules')) {
res.writeHead(404).end('Not found');
return;
}
try {
res.writeHead(200, { 'Content-Type': type }).end(await readFile(file));
} catch {
res.writeHead(404).end('Not found');
}
}).listen(8080, () => console.log('Serving on http://localhost:8080'));
JSThe server only hands out the five file types it knows, and sends each with the right Content-Type. Two of those matter for this tutorial: the manifest goes out as application/manifest+json, and the service worker as JavaScript. A browser refuses to register a service worker served with the wrong type. Any static host does the same job; this one keeps everything in one folder you can read.
Start it in a second terminal window and leave it running:
cd ~/bus-times-pwa
node server.mjsBack in the first terminal, ask for the page:
curl -s http://localhost:8080/ | grep '<title>'Check it worked
The second terminal shows Serving on http://localhost:8080, and the curl line prints <title>Ridgeway Bus Times</title>. Open http://localhost:8080 in your browser: you see the heading, the route line and a five-row timetable.
Step 2 · See why the origin must be secure
Installable apps can run in the background, receive push messages and keep data, so browsers only allow them on origins where the code cannot be tampered with in transit. That means HTTPS, with one exception for development: localhost, 127.0.0.1 and [::1] are treated as secure even over plain HTTP, because the traffic never leaves your machine.
Open your browser's developer tools on http://localhost:8080, go to the Console and type:
window.isSecureContextNow find your computer's address on the local network (in your system's network settings, something like 192.168.1.23) and open http://<that address>:8080 in the same browser, replacing the address with yours. Run the same line in its console, then 'serviceWorker' in navigator.
This is the catch when you test on a phone. Your phone reaches the laptop by its network address, not as localhost, so the page it loads is not a secure context and nothing in this tutorial works there. The install step shows two ways round that: forward the port so the phone sees localhost, or put the site on HTTPS.
Check it worked
On localhost, window.isSecureContext is true. On the network address it is false, and 'serviceWorker' in navigator is also false: the API is not even there to call. The check script later in this tutorial tests both cases for you.
Step 3 · Install Playwright and generate the icons
A home screen needs square PNG icons. Chrome's install check wants at least a 192 by 192 and a 512 by 512 pixel icon. You also want two variants that are easy to get wrong:
- A maskable icon. Android cuts icons into a circle, a squircle or a rounded square depending on the phone. A maskable icon fills the whole square with its background colour and keeps the artwork inside the central safe zone, a circle with a radius of 40 percent of the icon's width, so no mask crops it.
- An Apple touch icon, 180 by 180 pixels with no transparency. iOS rounds the corners itself and fills transparent areas with black.
If a designer gives you these files, put them in icons/ and skip the script. Here you draw a simple bus as SVG and let Playwright render it to PNG at each size, which also installs the browser used for the checks later. --with-deps installs the system libraries Chromium needs on Linux, and can ask for your password:
cd ~/bus-times-pwa
npm init -y > /dev/null
npm install playwright@1.65.1
npx playwright install --with-deps chromiumWrite the icon script:
cd ~/bus-times-pwa
cat > make-icons.mjs <<'JS'
import { chromium } from 'playwright';
import { mkdir } from 'node:fs/promises';
const bg = '#0f5e5a';
const fg = '#ffffff';
// A bus front on a 100 by 100 grid.
const bus = `
<rect x="22" y="18" width="56" height="58" rx="10" fill="${fg}"/>
<rect x="29" y="27" width="42" height="22" rx="3" fill="${bg}"/>
<circle cx="33" cy="63" r="4" fill="${bg}"/>
<circle cx="67" cy="63" r="4" fill="${bg}"/>
<rect x="28" y="74" width="10" height="10" rx="3" fill="${fg}"/>
<rect x="62" y="74" width="10" height="10" rx="3" fill="${fg}"/>`;
// "any": rounded tile, transparent corners, artwork at full size.
const anyIcon = `<rect width="100" height="100" rx="22" fill="${bg}"/>${bus}`;
// "maskable" and Apple: full-bleed square, artwork shrunk to 80 percent
// so every point stays inside the 40 percent safe-zone circle.
const fullBleed = `<rect width="100" height="100" fill="${bg}"/>
<g transform="translate(50 50) scale(0.8) translate(-50 -50)">${bus}</g>`;
const icons = [
{ file: 'icon-192.png', size: 192, art: anyIcon, transparent: true },
{ file: 'icon-512.png', size: 512, art: anyIcon, transparent: true },
{ file: 'icon-maskable-512.png', size: 512, art: fullBleed, transparent: false },
{ file: 'apple-touch-icon.png', size: 180, art: fullBleed, transparent: false },
];
await mkdir('icons', { recursive: true });
const browser = await chromium.launch();
const page = await browser.newPage();
for (const { file, size, art, transparent } of icons) {
await page.setViewportSize({ width: size, height: size });
await page.setContent(`<body style="margin:0">
<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" viewBox="0 0 100 100" style="display:block">${art}</svg></body>`);
await page.screenshot({ path: `icons/${file}`, omitBackground: transparent });
console.log(`icons/${file}`);
}
await browser.close();
JS
node make-icons.mjs
ls -l iconsCheck it worked
The script prints four paths and ls lists apple-touch-icon.png, icon-192.png, icon-512.png and icon-maskable-512.png, each a few kilobytes. Open http://localhost:8080/icons/icon-512.png in the browser: a white bus front on a dark teal rounded tile. The maskable one at http://localhost:8080/icons/icon-maskable-512.png is a plain teal square with a smaller bus in the middle, leaving a wide margin all round.
Step 4 · Write the web app manifest
The manifest is a JSON file that tells the browser what to call the app, which icons to use and how to open it. Save it as manifest.webmanifest, the extension the specification registers for it:
cd ~/bus-times-pwa
cat > manifest.webmanifest <<'JSON'
{
"name": "Ridgeway Bus Times",
"short_name": "Bus Times",
"description": "Weekday times for Ridgeway town buses.",
"id": "/",
"start_url": "/?source=pwa",
"scope": "/",
"display": "standalone",
"background_color": "#ffffff",
"theme_color": "#0f5e5a",
"lang": "en",
"icons": [
{ "src": "/icons/icon-192.png", "sizes": "192x192", "type": "image/png" },
{ "src": "/icons/icon-512.png", "sizes": "512x512", "type": "image/png" },
{ "src": "/icons/icon-maskable-512.png", "sizes": "512x512", "type": "image/png", "purpose": "maskable" }
]
}
JSONWhat each member is for:
nameappears in install dialogs, on the splash screen and in app lists.short_namegoes under the home screen icon, where there is room for roughly 12 characters before it is cut off, so keep it short and test it in every language you ship. A Swahili or Hausa label is often longer than the English one.idis the app's identity. Without it, the browser usesstart_url, so changing the start URL later would look like a different app and could leave users with two icons. Setting it once to/avoids that.start_urlis the page the icon opens. The?source=pwatag lets your analytics tell installed launches from browser visits; the server ignores it.scopelimits which URLs belong to the app. Links outside it open in the normal browser.display: standaloneremoves the browser's address bar and buttons, so the app gets its own window.minimal-uikeeps a small set of navigation controls, andbrowsermeans no app window at all, which also means Chrome will not offer an install.theme_colortints the title bar or status bar.background_colorfills the splash screen Android shows while the page loads, so match it to your page background.iconslists the PNGs. Withoutpurpose, an icon is foranyuse. The maskable one is listed separately; do not mark a single icon as"any maskable", because the margin that suits a mask looks too small as a normal icon.
Check it worked
Open http://localhost:8080/manifest.webmanifest. The browser shows or downloads the JSON. If it shows an error page instead, check the file name: the server only serves the .webmanifest extension. A JSON mistake such as a trailing comma does not show here; the script in the check step catches it.
Step 5 · Link the manifest from the page
The browser only finds the manifest through a <link rel="manifest"> in the page head. Rewrite index.html with the link and the other head tags:
cd ~/bus-times-pwa
cat > index.html <<'HTML'
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Ridgeway Bus Times</title>
<link rel="manifest" href="/manifest.webmanifest">
<meta name="theme-color" content="#0f5e5a">
<link rel="icon" href="/icons/icon-192.png" type="image/png">
<link rel="apple-touch-icon" href="/icons/apple-touch-icon.png">
<meta name="apple-mobile-web-app-title" content="Bus Times">
<link rel="stylesheet" href="/style.css">
<script src="/app.js" defer></script>
</head>
<body>
<main>
<h1>Ridgeway Bus Times</h1>
<p class="note">Route 4 · Market Square to Hillside · weekdays</p>
<table>
<thead><tr><th scope="col">Market Square</th><th scope="col">Clinic</th><th scope="col">Hillside</th></tr></thead>
<tbody>
<tr><td>06:40</td><td>06:52</td><td>07:05</td></tr>
<tr><td>07:20</td><td>07:32</td><td>07:45</td></tr>
<tr><td>08:00</td><td>08:14</td><td>08:28</td></tr>
<tr><td>12:30</td><td>12:42</td><td>12:55</td></tr>
<tr><td>17:10</td><td>17:24</td><td>17:38</td></tr>
</tbody>
</table>
</main>
</body>
</html>
HTMLThe manifest covers Chrome, Edge, Samsung Internet and Firefox on Android. The extra tags fill gaps:
theme-colortints the browser bar before anyone installs the app, and keeps the colour consistent with the manifest.apple-touch-iconis the icon iOS and iPadOS put on the Home Screen. Safari reads manifest icons too, but the touch icon is the one it has used longest, and it costs one line.apple-mobile-web-app-titlesets the label under the icon on Apple devices.
app.js does not exist yet. You write it in the next step.
Check it worked
Reload http://localhost:8080. The page looks the same, and the browser tab now shows the small bus icon. In Chrome or Edge, open developer tools and go to Application, then Manifest: it lists the name, short name, start URL, theme colour and all three icons, and the maskable one is marked as maskable. The console has one 404 error for app.js, which the next step removes.
Step 6 · Register a minimal service worker
A service worker is a script the browser runs separately from the page. It can intercept the page's network requests, which is how offline support works. Here it does nothing yet except exist and take control, so you can see the lifecycle working before you add caching.
cd ~/bus-times-pwa
cat > sw.js <<'JS'
// Version 1. Caching comes in the offline tutorial.
self.addEventListener('install', () => {
self.skipWaiting();
});
self.addEventListener('activate', (event) => {
event.waitUntil(self.clients.claim());
});
JS
cat > app.js <<'JS'
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker
.register('/sw.js')
.then((reg) => console.log('Service worker registered for', reg.scope))
.catch((err) => console.error('Service worker registration failed:', err));
});
}
JSSome details that cause most "it never registers" problems:
- Where
sw.jslives sets its reach. A worker at/sw.jscan control every page under/. The same file at/js/sw.jscould only control pages under/js/. Keep it at the root. - The feature check.
'serviceWorker' in navigatorisfalseon insecure origins and in old browsers, so the page still works there; it just is not installable. - Registering after
load. The worker starts without competing with the page's own first downloads, which helps on slow connections. - No
fetchhandler yet. An empty one would make every request pass through the worker for no benefit, and Chrome warns about it. The offline tutorial writes a worker with a real one.
skipWaiting() and clients.claim() make a new worker take over at once instead of waiting for every tab to close. That is fine for a worker that changes nothing. Once it caches files, you will want more control over updates.
Check it worked
Reload http://localhost:8080 and open the console: it logs Service worker registered for http://localhost:8080/. In developer tools, Application, then Service workers shows sw.js with a green dot and a status of activated and running.
Step 7 · Check the manifest and install readiness with scripts
Checking by eye catches mistakes once. Two scripts catch them every time someone edits the manifest or moves an icon.
The first uses only Node. It finds the manifest link in the page, fetches the manifest, parses it as JSON, checks the members Chrome requires for install, then downloads every icon and reads its real width and height from the PNG header, so an icon that claims to be 512 pixels but is not gets caught:
cd ~/bus-times-pwa
cat > check-manifest.mjs <<'JS'
import assert from 'node:assert/strict';
const base = process.argv[2] ?? 'http://localhost:8080/';
const html = await (await fetch(base)).text();
const href = html.match(/<link rel="manifest" href="([^"]+)"/)?.[1];
assert.ok(href, 'the page links a manifest');
const manifestUrl = new URL(href, base);
const res = await fetch(manifestUrl);
assert.equal(res.status, 200, 'manifest loads');
assert.match(res.headers.get('content-type'), /^application\/manifest\+json/);
const m = JSON.parse(await res.text());
for (const key of ['name', 'short_name', 'start_url', 'display', 'icons']) {
assert.ok(m[key], `manifest has ${key}`);
}
assert.ok(m.short_name.length <= 12, 'short_name fits under an icon');
assert.ok(['fullscreen', 'standalone', 'minimal-ui'].includes(m.display), 'display opens an app window');
assert.notEqual(m.prefer_related_applications, true);
assert.equal(new URL(m.start_url, manifestUrl).origin, manifestUrl.origin, 'start_url is on this site');
const found = [];
for (const icon of m.icons) {
const r = await fetch(new URL(icon.src, manifestUrl));
assert.equal(r.status, 200, `${icon.src} loads`);
const png = Buffer.from(await r.arrayBuffer());
assert.equal(png.toString('ascii', 1, 4), 'PNG', `${icon.src} is a PNG`);
const size = `${png.readUInt32BE(16)}x${png.readUInt32BE(20)}`;
assert.equal(size, icon.sizes, `${icon.src} really is ${icon.sizes}`);
const purpose = icon.purpose ?? 'any';
found.push(`${size} ${purpose}`);
console.log(`ok ${icon.src} ${size} ${purpose}`);
}
for (const need of ['192x192 any', '512x512 any', '512x512 maskable']) {
assert.ok(found.includes(need), `has a ${need} icon`);
}
console.log('PASS: manifest parses and every icon matches its size');
JS
node check-manifest.mjsThe second uses Playwright to ask Chromium itself. It loads the page, waits for the service worker, reloads to confirm the worker controls the page, and calls Page.getAppManifest from the Chrome DevTools Protocol, which returns the manifest the browser found and any errors it hit parsing it. Then it opens the same site through your network address to prove that origin is not secure:
cd ~/bus-times-pwa
cat > check-install.mjs <<'JS'
import { chromium } from 'playwright';
import assert from 'node:assert/strict';
import os from 'node:os';
const browser = await chromium.launch();
const context = await browser.newContext();
const page = await context.newPage();
await page.goto('http://localhost:8080/');
assert.equal(await page.evaluate(() => window.isSecureContext), true, 'localhost is secure');
const scope = await page.evaluate(async () => (await navigator.serviceWorker.ready).scope);
assert.equal(scope, 'http://localhost:8080/', 'worker controls the whole site');
await page.reload();
assert.ok(await page.evaluate(() => navigator.serviceWorker.controller !== null), 'page is controlled');
const cdp = await context.newCDPSession(page);
const { url, errors, data } = await cdp.send('Page.getAppManifest');
assert.equal(url, 'http://localhost:8080/manifest.webmanifest');
assert.deepEqual(errors, [], 'Chromium reports no manifest errors');
assert.equal(JSON.parse(data).short_name, 'Bus Times');
assert.equal(await page.locator('meta[name="theme-color"]').getAttribute('content'), '#0f5e5a');
console.log(`ok Chromium read ${url} with no errors`);
const lan = Object.values(os.networkInterfaces()).flat()
.find((i) => i && i.family === 'IPv4' && !i.internal);
if (lan) {
const remote = await context.newPage();
await remote.goto(`http://${lan.address}:8080/`);
assert.equal(await remote.evaluate(() => window.isSecureContext), false);
assert.equal(await remote.evaluate(() => 'serviceWorker' in navigator), false);
console.log(`ok http://${lan.address}:8080/ is not a secure context`);
}
await browser.close();
console.log('PASS: secure origin, service worker in control, manifest accepted');
JS
node check-install.mjsCheck it worked
check-manifest.mjs prints one ok line per icon, ending with PASS: manifest parses and every icon matches its size. check-install.mjs prints that Chromium read the manifest with no errors, that your network address is not a secure context, and ends with PASS: secure origin, service worker in control, manifest accepted. To see a failure, change "sizes": "192x192" to "sizes": "180x180" in the manifest and run node check-manifest.mjs: it stops with an AssertionError naming /icons/icon-192.png. Put it back before you continue.
Step 8 · Install it on a phone and a desktop
The install flow is up to each browser, and it differs more than anything else in this tutorial. First get the site onto a secure origin the device can reach:
- Android over USB. Turn on USB debugging on the phone, connect it, open
chrome://inspectin desktop Chrome, and under port forwarding map port8080tolocalhost:8080. Chrome on the phone can then openhttp://localhost:8080as a secure origin. This costs no mobile data at all. - Any device, including iPhone. Put the folder on any static host that serves HTTPS, or behind a server such as Caddy, which gets certificates for you. Make sure the host sends
.webmanifestfiles asapplication/manifest+json, then runnode check-manifest.mjs https://your-domain/against it, replacing the address with yours.
Then install:
- Android, Chrome and most Chromium browsers. Open the site. Chrome may show an install prompt at the bottom; if not, open the three-dot menu and choose the option to install the app or add it to the home screen (the wording varies by version). Android builds a proper app entry for it, with your maskable icon cut to the phone's shape and your
background_colorand icon as the splash screen. - iPhone and iPad, Safari. There is no prompt. Tap Share, then Add to Home Screen. From iOS 26 and iPadOS 26, every site added this way opens as a web app by default, with an Open as Web App switch in the dialog that the user can turn off. iOS uses
apple-touch-iconand theapple-mobile-web-app-titlelabel. Other browsers on iOS offer the same action through their share menu. - Desktop Chrome and Edge. An install icon appears at the right of the address bar, and the browser menu has an install item. The app opens in its own window with the title bar in your
theme_color. - Safari on macOS. Choose File, then Add to Dock. The app gets its own window and Dock icon.
If Chrome does not offer an install, open developer tools, go to Application, then Manifest: any missing requirement is listed under Installability. On a phone, remember that the browser also hides its prompt until the user has interacted with the page, so tap the page once and wait.
Check it worked
The bus icon is on your home screen or in your dock, labelled Bus Times. Tap or click it: the timetable opens in a window with no address bar, and on Android the status bar is dark teal. On Android, the icon matches the shape of the other icons on the screen with the bus fully visible, which is the maskable icon at work.
Step 9 · Clean up
If you installed the app, uninstall it the same way as any other: long-press the icon on Android or iOS and remove it, or open the app window's menu on desktop and choose uninstall.
The service worker stays registered in your desktop browser after the server stops, and the offline tutorial uses the same port. While http://localhost:8080 is still open, go to developer tools, Application, then Storage, and choose Clear site data. (Application, then Service workers, then Unregister removes just the worker.)
Then stop the server with Ctrl+C in its terminal.
Remove the demo folder, which also removes the local Playwright install. The browser Playwright downloaded stays in its shared cache; npx playwright uninstall removes that too if you no longer need it.
The offline tutorial builds its own copy of the site in a new folder, so you can remove this one even if you are going straight on.
cd ~
rm -rf ~/bus-times-pwaCheck it worked
ls ~/bus-times-pwa reports that there is no such file or directory, and http://localhost:8080 no longer loads. In developer tools, Application, then Service workers shows no worker for localhost:8080.
Next steps
- Make the timetable load with no connection at all in make pages work offline with a service worker and the Cache API.
- Plan for the people most likely to install it in design for slow networks and costly data.
- Measure how the page behaves on a throttled phone connection in test and speed up a page on a slow phone connection.
- Put the site on HTTPS with certificates handled for you in automatic HTTPS with Caddy 2.
Part of these paths
Related tutorials
- Make pages work offline with a service worker and the Cache APIYou will write a service worker by hand that precaches a small timetable site, serves files cache-first and pages network-first with a timeout, shows an offline page, offers a Reload when a new version is waiting, and passes a Playwright test with the network switched off.
- Design for slow networks and costly dataYou will have a per-screen data budget for the Larkfield Clinic booking flow, Figma frames for what each screen shows offline, a save-and-resume state, a use-less-data option and SMS confirmation text that fits in one message.
- Test and speed up a page on a slow phone connectionYou will measure a heavy clinic home page on a throttled slow mobile connection, set a 500 kB page weight budget with a check that fails when the page grows, and cut its images, JavaScript and third-party widget until it passes, with before and after numbers to show for it.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials