Fix Lighthouse timeout on pages with video players #6704
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, Lighthouse will consistently timeout when run against any website page that uses our VideoPlayer module. This is because of a potential infinite loop in its JS code that can be triggered by a certain Lighthouse test. This commit fixes that bug and allows for successful audits of these pages with Lighthouse.
See here for an example of a failing Lighthouse test on one of these pages.
The reason for the failures is down in the Lighthouse code -- currently LH runs an audit called
redirects-http
that verifies that a request to a URL with HTTP always gets redirected to HTTPS. Instead of using a HEAD request or something similar to check this, it tries making the request in Chrome. To speed up what is an expected redirect, the request disables the loading of certain assets in Chrome, including images.Image loading being disabled seems to trigger some error handling code we have in the VideoPlayer: if the video thumbnail image fails to load, we load a default thumbnail. Currently, though, this is implemented with the
'error'
listener of the<img>
tag, which means that if all image loads are disabled, there will be an infinite loop of errors:This causes Lighthouse to timeout when run in the console and essentially hang forever when run in the browser.
This commit changes the logic so that we don't try loading the default thumbnail if we've already tried and failed to do so once.
How to test this PR
To test this change, first verify that Lighthouse hangs against production:
Then run a local server with this change (first build using
yarn run gulp scripts
) and confirm that it works properly:Notes
Edit to add: it looks like
redirects-http
is scheduled to be removed in the next major version of Lighthouse.Checklist