Puppeteer and ServiceWorkers offline mode
See original GitHub issueSteps to reproduce
Tell us about your environment:
- Puppeteer version: 1.3.0
- Platform / OS version: CentOS 7 x64
- URLs (if applicable): -
- Node.js version: 8.11.1
What steps will reproduce the problem?
Please include code that reproduces the issue.
- Initialise empty project with puppeteer
- Create test file with following content
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({ args: ['--no-sandbox']});
const page = await browser.newPage();
page.on('console', msg => console.log('PAGE LOG:', msg.text()));
await page.goto('https://googlechrome.github.io/samples/service-worker/custom-offline-page/', { waitUntil: 'networkidle0' });
console.log('Setting app offline');
await page.setOfflineMode(true);
await page.waitFor(1*2000);
await page.reload();
await page.waitFor(1*2000);
await page.screenshot({path: 'test.png'});
});
- Check the resulting screenshot, the page was reloaded but the offline mode was not applied.
What is the expected result?
The resulting screenshot will contain offline page as in classic example https://googlechrome.github.io/samples/service-worker/custom-offline-page/
What happens instead?
Seems like the offline mode is not applied and the page is loaded regularly.
StackOverflow question for reference: Service worker installation in Headless Chrome (via puppeteer)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:15 (7 by maintainers)
Top Results From Across the Web
Service worker not activated in Puppeteer for localhost domain
The service worker I'm talking about here is from a chrome extension (background script). Because it is the background script from a chrome ......
Read more >Making PWAs work offline with Service workers
In this article we took a simple look at how you can make your PWA work offline with service workers. Be sure to...
Read more >What is a service worker ? | Browser - Data and Co
https://github.com/puppeteer/examples/blob/master/verify_sw_caching.js - Verify all the resources you expect are being cached by a service worker for offline.
Read more >Service Worker - ITNEXT
Read writing about Service Worker in ITNEXT. ... Go to the profile of Kjartan Rekdal Müller ... Interacting with Service Workers using Puppeteer....
Read more >Use Service Workers to manage network requests and push ...
You can use the install event to pre-cache any important and long-lived files, such as CSS files, JavaScript files, logo images, offline pages, ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Is there any update on how to run offline tests that also disable the network for service workers?
Yea this is weird. I’d expect this example to work as you’ve outlined.
The main page gets cached offline (expected) but it appears the SW isn’t intercepting the network requests, and therefore, not serving the fallback content.
Slightly modified repro.