Closed ajohnson052 closed 4 years ago
try a "Network.enable" previous to the emulate call?
It's a bit atypical, but we know that Network.setUserAgent
doesn't succeed without Network.enable
first.
Thanks for the suggestion! Unfortunately, I don't see any change in behavior after sending Network.enable
to both the pageSession
and the serviceWorkerSession
.
Any other ideas we should try?
I'm also expereincing this issue. Tried with and without calling Network.enable
before calling Network.emulateNetworkConditions
. It successfully works if devtools is open but not if it's closed.
.
I'm encountering something similar if not the same. Emulating browser conditions for service worker targets is crucial for our app; there don't seem to be any other decent ways to write e2e tests that get at offline functionality of service workers.
From looking into this problem, I've learned that service workers don't have a javascript runtime of their own. Instead, they use a dedicated web worker for executing javascript, and if you want to execute javascript in the service worker via CDP, you must send a Runtime.enable
command first. Maybe the devtools UI does the equivalent of sending Runtime.enable
to the service worker, and that's what we're missing in our approach.
@tysoeh Tried what you've suggested by sending Runtime.enable but that didn't seem to fix the issue.
I'm using Cypress with Electron 76 (also tested using Chrome 72 and Chromium 76) for my e2e tests. I'll try and explain the process I'm using for this.
Network.emulateNetworkConditions
Again, this only seems to work if devtools has been opened before Network.emulateNetworkConditions
is sent.
If devtools has not been opened, window.navigator.onLine
evaluates to false after sending Network.emulateNetworkConditions
, but the page can still fetch data.
If devtools is open, window.navigator.onLine
also evaluates to false but the page is blocked from fetching data.
Hopefully this information can help someone with more knowledge of the DevTools Protocol narrow down the issue.
This repository is related to Chrome DevTools Protocol, but does not track issues regarding its definition or implementation. If you want to file an issue for the Chrome DevTools Protocol, please open an issue on https://crbug.com under component: Platform>DevTools>Platform
. Thanks in advance!
The problem as we understand it:
Network.emulateNetworkConditions
commands don't appear to be put into effect by the browser unless:the devtools UI is already open when the protocol message is sent
the devtools UI is opened sometime after
Network.emulateNetworkConditions
is sent (in which case it's put into effect at that time)What we want:
To write a headless test that toggles both the browser and our service worker offline in order to test offline functionality of our service worker
What we tried:
With this script we have seen a POST request enqueued in indexedDB (which is what we would expect if the user was indeed offline).
However, if we use
puppeteer.launch()
with{ devtools: false }
, or with{ headless: true }
, our POST request is not enqueued.Perhaps we're neglecting to enable some feature of our page or service worker. Is this expected behavior?