-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
web.dev consistently errors on Network.getResponseBody for main content #10876
Comments
We are experiencing the same issue with the lighthouse npm package. leaving a comment to follow this thread. |
btw I noticed that our service worker was being too aggressive (GoogleChrome/web.dev#3089). @brendankenny I tried to use canary to audit our staging server (https://web-dev-staging.appspot.com/) since it doesn't install the sw, but got an error |
should get fixed for next chromium canary |
Running into this too for the first time today. I got scored 0 for "Best Practices" when analyzing this website: https://nrn-v2-mst-aptd-at-lcz-sty-c1-ah8bmgx1e.vercel.app/en |
We're also running into this problem at modern-web.dev: It seems like disabling the service worker 'fixes' the problem. We dont do anything fancy with our service worker — we either load an index.html either from network or from cache, we dont do any transformations on the html or anything like that. I really fail to see the connection between the service worker and defining a charset in the html |
Certain service workers mean that Lighthouse cannot fetch the HTML document to check for a charset. |
We debugged a little bit more, we use a code snippet to reload the page when a new service worker has taken over: if("serviceWorker"in navigator){let e;navigator.serviceWorker.addEventListener("controllerchange",()=>{e||(e=!0,window.location.reload())})} ❌ With that piece of code: ✅ Without that piece of code: It seems that the reload is causing the best practices to error, hope that helps 🙂 EDIT: In case anybody wants to workaround this, this seems to fix it. Also skips an unnecessary reload the first time a user visits your app (even though its so fast you might not have noticed) async function handleUpdate() {
if ("serviceWorker"in navigator) {
let refreshing;
const oldSw = (await navigator.serviceWorker.getRegistration())?.active?.state;
navigator.serviceWorker.addEventListener('controllerchange', async () => {
if (refreshing) return;
const newSw = (await navigator.serviceWorker.getRegistration())?.active?.state;
if(oldSw === 'activated' && newSw === 'activating') {
refreshing = true;
window.location.reload();
}
});
}
}
handleUpdate(); |
Ah thanks @thepassle that helps a lot! I think this is happening because Chrome might only keep the network resources from the current page load in the memory cache which is what Lighthouse relies on to get the response body of the root document. We can do a bit more digging but this is a great head start 👍 |
We use a similar snippet on web.dev |
I run into this issue and made some debugging. I confirmed what @patrickhulce suggested. The problem is in
When reload is performed EDIT: |
I have the same problem, it's not only visible on my website. I have a more extensive worker service. Which is only a transitional version anyway. Can anyone help me solve the coding problem or improve the worker code? My website https://i-meble.eu |
@frankii91 The issue is not reproducible on that site |
The fix appears in version 11.1.0, PSI and the Chrome extension still use 11.0.0 |
@adamraine got another report for this site: https://leverx.com/ Testing it locally in Chrome (on 11.3.0) the error still shows. Any ideas why? |
@tunetheweb looks like a different issue that is reproducible without Lighthouse. I'll open a new issue since this one is pretty old. |
node lighthouse-cli/index.js https://web.dev --only-categories best-practices --view
Properly defines charset – Error!
(also happens in DevTools and PSI)
Example report
The error is
Required MainDocumentContent gatherer encountered an error: Protocol error (Network.getResponseBody): No resource with given identifier found
and occurs here in
driver
when called frommain-document-content
.It seems unusual that the main document content wouldn't be available for the backend. @robdodson does mention some unusual things done with the service worker and "an app shell that pulls in an index.json of the page content when you go to other pages. We essentially replace main content area with this new content" that could be causing trouble (maybe the request really didn't have any content?).
The text was updated successfully, but these errors were encountered: