Chrome DevTools provides dedicated panels for debugging PWAs:
// Add logging in Service Worker for easier debugging
const DEBUG = true;
function log(...args) {
if (DEBUG) {
console.log('[SW]', ...args);
}
}
self.addEventListener('install', (event) => {
log('Installing...');
// ...
});
self.addEventListener('fetch', (event) => {
log('Fetch:', event.request.url);
// ...
});
// To see SW logs:
// 1. Open DevTools > Application > Service Workers
// 2. Click "Inspect" to open the SW console
// 3. All console.log calls from the SW appear here
# Run Lighthouse from CLI
npm install -g lighthouse
lighthouse https://my-pwa.com --view
# Or use in CI
lighthouse https://my-pwa.com \
--chrome-flags="--headless" \
--output=json \
--output-path=./report.json \
--preset=desktop
// Using Puppeteer for PWA testing
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
// Enable DevTools Protocol for SW inspection
const cdp = await page.target().createCDPSession();
await cdp.send('ServiceWorker.enable');
// Listen for SW events
cdp.on('ServiceWorker.workerRegistrationUpdated', (event) => {
console.log('Registrations:', event.registrations);
});
await page.goto('https://my-pwa.com');
// Check if SW is active
const hasSW = await page.evaluate(() => {
return 'serviceWorker' in navigator;
});
console.log('Has Service Worker:', hasSW);
// Test offline behavior
await page.setOfflineMode(true);
await page.reload({ waitUntil: 'networkidle0' });
const bodyText = await page.evaluate(() => document.body.innerText);
console.log('Offline content:', bodyText);
await browser.close();
})();
| Check | How to Verify |
|---|---|
| HTTPS | Check URL bar for lock icon |
| Manifest valid | DevTools > Application > Manifest |
| SW registered | DevTools > Application > Service Workers |
| Offline page | Go offline in DevTools, reload |
| Fast load | Lighthouse performance audit |
| Install prompt | Trigger beforeinstallprompt |
| Responsive | Device toolbar in DevTools |
| Accessible | Lighthouse accessibility audit |