question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

web.dev consistently errors on Network.getResponseBody for main content

See original GitHub issue
  • run node lighthouse-cli/index.js https://web.dev --only-categories best-practices --view
  • get Properly defines charset – Error!

(also happens in DevTools and PSI)

lighthouse error

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 from main-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?).

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:5
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
patrickhulcecommented, Aug 28, 2020

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 👍

related #8984 #11027

2reactions
thepasslecommented, Aug 28, 2020

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:

Screenshot 2020-08-28 at 12 55 47

Without that piece of code:

Screenshot 2020-08-28 at 13 02 51

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();
Read more comments on GitHub >

github_iconTop Results From Across the Web

Chrome Extension: "No resource with given identifier found ...
It was because the website sends many responses, and this code will see another request other than I want, then detach the debugger...
Read more >
Network.getResponseBody - Vanilla Protocol Viewer
Fired when WebSocket message error occurs. Parameters. errorMessage. stringWebSocket error message. requestId. Network.RequestIdRequest identifier. timestamp.
Read more >
Network domain - Chrome DevTools Protocol - GitHub Pages
Chrome DevTools Protocol - version tot - Network domain. ... Identifier of the network request to get content for. ... Always set to...
Read more >
HTTP Messages - MDN Web Docs - Mozilla
Web developers, or webmasters, rarely craft these textual HTTP messages ... data associated with the request (like content of an HTML form), ...
Read more >
Fetch - The Modern JavaScript Tutorial
Fetch. JavaScript can send network requests to the server and load new information whenever it's needed. For example, we ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Hashnode Post

No results found