Skip to content
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

Lighthouse in DevTools errors/hangs on installability checks #13396

Closed
connorjclark opened this issue Nov 19, 2021 · 13 comments
Closed

Lighthouse in DevTools errors/hangs on installability checks #13396

connorjclark opened this issue Nov 19, 2021 · 13 comments
Assignees

Comments

@connorjclark
Copy link
Collaborator

connorjclark commented Nov 19, 2021

Latest:

We have a fix that should land in Canary ~soon: chromium-review.googlesource.com/c/chromium/src/+/3318838

We'll request a merge to Chrome 97 (scheduled to release Jan 4).

In the meantime, you can avoid the hanging by disabling Clear Storage
image


Before 98.0.4711.0, some sites with service workers would hang indefinitely while determining if there were any installability errors. With 98.0.4711.0, hanging should occur less often (these issues were fixed), a report will be generated and this error will be seen in the installable audit: Lighthouse could not determine if there was a service worker. Please try with a newer version of Chrome.. This message is aspirational, as there is not yet a fix for the underlying cause.

However, there are still URLs that will hang indefinitely:

Debugging shows that the target for the service worker is never resumed.

Some URLs that will show the new could not determine message (and not hang):

related crbug: https://bugs.chromium.org/p/chromium/issues/detail?id=1276339

@chrisbennett-Bene
Copy link

chrisbennett-Bene commented Nov 21, 2021

Tried on Canary 98.0.4719.0. Still won't complete but at least could cancel and see console.
Console error popped at the moment Lighthouse stalls.

Service worker registration failed or was blocked by your browser settings: DOMException: Failed to register a ServiceWorker for scope ('https://www.alfresco-bar-bistro.com.au/') with script ('https://www.alfresco-bar-bistro.com.au/sw-6.2.0.v1.00.js'): Operation has been aborted

On 2 attempts after that, left it run to see what happened and got this reproducible error, so duly reporting as requested.


PROTOCOL_TIMEOUT

Channel: DevTools
Initial URL: https://www.alfresco-bar-bistro.com.au/
Chrome Version: 98.0.4719.0
Stack Trace: LHError: PROTOCOL_TIMEOUT
at devtools://devtools/bundled/devtools-frontend/front_end/third_party/lighthouse/lighthouse-dt-bundle.js:146:58
at new Promise ()
at Driver$1.sendCommandToSession (devtools://devtools/bundled/devtools-frontend/front_end/third_party/lighthouse/lighthouse-dt-bundle.js:146:10)
at Driver$1.sendCommand (devtools://devtools/bundled/devtools-frontend/front_end/third_party/lighthouse/lighthouse-dt-bundle.js:146:257)
at ExecutionContext$2._evaluateInContext (devtools://devtools/bundled/devtools-frontend/front_end/third_party/lighthouse/lighthouse-dt-bundle.js:108:795)
at ExecutionContext$2.evaluateAsync (devtools://devtools/bundled/devtools-frontend/front_end/third_party/lighthouse/lighthouse-dt-bundle.js:109:403)
at ExecutionContext$2.evaluate (devtools://devtools/bundled/devtools-frontend/front_end/third_party/lighthouse/lighthouse-dt-bundle.js:109:772)
at getBenchmarkIndex$2 (devtools://devtools/bundled/devtools-frontend/front_end/third_party/lighthouse/lighthouse-dt-bundle.js:98:32)
at Function.run (devtools://devtools/bundled/devtools-frontend/front_end/third_party/lighthouse/lighthouse-dt-bundle.js:212:827)
at async Function._gatherArtifactsFromBrowser (devtools://devtools/bundled/devtools-frontend/front_end/third_party/lighthouse/lighthouse-dt-bundle.js:358:413)

May be of interest that it appears that after each of these failed attempts at Lighthouse audits, Canary is unable to load the service worker properly, even with a hard refresh until I close devtools.

Once that is done, devtools can be reopened and service worker happily loads again as expected.

@mikkopori
Copy link

Tried on Version 98.0.4710.4 (Official Build) dev (64-bit) on Ubuntu

and also getting hanged with this in the console:

Error during service worker registration: DOMException: Failed to register a ServiceWorker for scope ('http://localhost:3000/') with script ('http://localhost:3000/sw.js'): Operation has been aborted

Was able to cancel also.

@theshanergy
Copy link

theshanergy commented Nov 28, 2021

I am getting FID issue: longer than 100ms (mobile) errors site-wide on Google Search Console Core Web Vitals corresponding to this bug appearing. I believe it to be related to the service worker failing to load though I am not certain. Can anyone else confirm whether they are seeing this in their Search Console at the moment?

@connorjclark
Copy link
Collaborator Author

# python bisect-builds.py -o --verify-range -a mac -g 857950 -b 929940 --use-local-cache --not-interactive -c "bash $PWD/scripts/cdt-manifest-install-errors-hang/script.sh %p"

LH=~/src/lighthouse

export CHROME_PATH=$1

# brew install coreutils

cd $LH
pwd
if gtimeout 30 yarn run-devtools 'https://www.enricofromrome.eu/edb6/'; then
  echo "ok $1"
  exit 0
else
  echo "bad $1"
  exit 1
fi

result: https://chromium.googlesource.com/chromium/src/+log/1abcb14aea6f33b2f0e09fef09755d189b426f5f..38d1dcf838c6a49d59244c768d57638c7e34a7b8

Does not hang with this Chrome flag: --disable-features=PlzServiceWorker

@paulirish
Copy link
Member

Does not hang with this Chrome flag: --disable-features=PlzServiceWorker

HUGE FIND.

This is definitely key. We've since followed up with some chromium folks to better understand what its all about.

@paulirish
Copy link
Member

I've added some basic printf logging to the installability manager in Chromium to better understand what's happening.

The repro is basically: open https://caltrainschedule.io/ . open devtools. lighthouse panel. just pwa. hit analyze. this will hit our protocol_timeout case.

But now with Chromium logging there's something more interesting going on.

In a happy run (with PlzServiceWorker) it looks like this:

  • lighthouse loads up about:blank twice. each time, chromium's AppBannerManager::RequestAppBanner is called which gathers just the eligibility items. (AFAIK, this is done fairly eagerly w/ every load in case chrome wants to change the omnibox color to matches the manifest theme color).
  • then LH has chrome navigate to the PWA (caltrainsched) and now chromium again automatically runs AppBannerManager::RequestAppBanner which is done in 100ms.
  • because Chrome thinks this may potentially be installable, it continues with the rest of the installability checks aka AppBannerManager::PerformInstallableWebAppCheck. This does look at the serviceworker (the most involved check).
    • PerformInstallableWebAppCheck takes 200ms. Within that, the serviceworker inspection takes 25ms.
  • 7 seconds after all that, along comes Lighthouse very curious about the installability situation. it calls the Page.getInstallabilityErrors CDP method and that triggers a fresh call to InstallableManager::GetData that wants the exact information that AppBannerManager had just received (7s ago).
  • InstallableManager obliges and returns the cached data and 1ms later it's sent back over the protocol to Lighthouse who is so happy. It's an empty array cuz this PWA is indeed installable. :)

in a sad, hanging run though:

  • same first 3 bullets.
    • HOWEVER.... the 3rd bullet (PerformInstallableWebAppCheck) hasn't finished yet when LH's CDP request comes along. It's stuck on CheckServiceWorker().
    • This time, PerformInstallableWebAppCheck takes 38 seconds. Within that, the serviceworker inspection takes 37 seconds.
  • CDP eventually returns a response, but its been more than LH's DEFAULT_PROTOCOL_TIMEOUT of 30 seconds. So LH has no idea.

Also different this time:

  • After 37s of CheckServiceWorker() shenanigans it goes down a new OnWaitingForServiceWorker() route. That ends up going back into CheckServiceWorker() but this time it's done in ~10ms.
  • Uncaught (in promise) AbortError: Failed to register a ServiceWorker for scope ('https://caltrainschedule.io/') with script ('https://caltrainschedule.io/sw.js'): Operation has been aborted", in the console.
    • because the SW is in a failure state, the CDP method includes that in the installabilityErrors payload: ['no-matching-service-worker]

@connorjclark
Copy link
Collaborator Author

connorjclark commented Dec 2, 2021

current theory is that the SW target is paused. Targets are resumed when we attach but for some reason we don't get the opportunity to resume the target dealing with this SW network fetch, which now happens in the browser. If you turn off the waitForDebuggerOnStart on autoAttach in target managers on frame navigated, then the hang does not happen ...

waitForDebuggerOnStart: true,

@connorjclark
Copy link
Collaborator Author

If I avoid our usage of Storage.clearDataForOrigin there is no hanging! So that seems important.

I found that when replaying a log of CDT protocol commands (from a hanging repro), and filtering out all the methods I could while keeping the hanging reproduction.

@connorjclark
Copy link
Collaborator Author

connorjclark commented Dec 7, 2021

We have a fix that should land in Canary ~soon: https://chromium-review.googlesource.com/c/chromium/src/+/3318838

We'll request a merge to Chrome 97 (scheduled to release Jan 4).

In the meantime, you can avoid the hanging by disabling Clear Storage
image

@connorjclark
Copy link
Collaborator Author

Confirmed with latest Canary 98.0.4755.0 that all the URLs in the original post work, and none return the temporary error message.

Will keep this open to track the merge into Chrome 97 and (maybe) 96.

@paulirish
Copy link
Member

Merged to 97: https://bugs.chromium.org/p/chromium/issues/detail?id=1276339#c30

I don't see any pending stuff on m96 merge tho.

@connorjclark
Copy link
Collaborator Author

connorjclark commented Jan 5, 2022

The fix has reached stable.

@enricofromrome
Copy link

No changes in my software ('https://www.enricofromrome.eu/edb6/') and now, on chrome 97 it works. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants