fix(cwv): filter out 4xx URLs from CWV opportunities (SITES-40803)#2034
Open
tathagat2241 wants to merge 2 commits intomainfrom
Open
fix(cwv): filter out 4xx URLs from CWV opportunities (SITES-40803)#2034tathagat2241 wants to merge 2 commits intomainfrom
tathagat2241 wants to merge 2 commits intomainfrom
Conversation
…only audit result
|
This PR will trigger a patch release when merged. |
ramboz
reviewed
Feb 26, 2026
ramboz
left a comment
There was a problem hiding this comment.
Looks good overall!
We could consider centralizing the logic though to limit code duplication across tracks and simplify maintenance long-term
| redirect: 'follow', | ||
| signal: controller.signal, | ||
| headers: { | ||
| 'User-Agent': 'Mozilla/5.0 (compatible; Spacecat-Audit/1.0)', |
There was a problem hiding this comment.
I wonder if we should maybe centralize the user agents we use somewhere so everybody uses the same one.
I also noticed that the internal links also use a HEAD request approach to validate links:
Maybe worth thinking about creating a more centralized helper for both actually to avoid code duplication
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Filters out URLs that return 4xx (or where HEAD request fails) so they are not turned into CWV opportunities. Addresses issue where 404/clientlib/sling URLs were appearing as CWV opportunities.
Changes
src/cwv/cwv-audit-result.js: AddedisUrl4xxOrFailed(url, log)that performs a HEAD request to the URL; if the response is 4xx or the request fails (timeout/network), the URL is excluded. After building the filtered CWV list (homepage + top N + threshold), URL-type entries are checked via HEAD and 4xx/failed URLs are removed before the audit result is returned. Group entries are not HEAD-checked.src/cwv/opportunity-sync.js: Guard when computingmaxOrganicForUrlsso that when there are no URL entries (e.g. all filtered as 4xx), we use0instead ofMath.max(...[])(-Infinity).test/audits/cwv/cwv-audit-result.test.js: Unit tests forisUrl4xxOrFailed(404, 403, 410, 200, 500, fetch throw) and forbuildCWVAuditResult(4xx URLs excluded from result, group entries kept without HEAD check).Behavior
auditResult.cwv, so they never become suggestions or part of the CWV opportunity.Please ensure your pull request adheres to the following guidelines:
Related Issues
https://jira.corp.adobe.com/browse/SITES-40803
Thanks for contributing!