-
Notifications
You must be signed in to change notification settings - Fork 9.6k
core(image-size-responsive): use real mimeType to exclude svg #16443
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
Conversation
The current audit relies on guessing MimeType based on file extension. This can lead to inaccurate results for dynamically generated files since file extension is not guaranteed. This commit retrieves the real mimeType, while preserving the existing guess approach.
connorjclark
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks!
BTW this audit will be removed in the near future, but the replacement insight audit image-delivery-insight is already good in this respect.
|
I couldn't push to your branch - can you please run this to fix the tests?
|
yarn update:sample-json yarn mocha api-test-pptr -u
|
Sure - I guess I should commit the resulting changes to my branch... hopefully that's the right step. Note the However, the |
| "image-alt", | ||
| "image-aspect-ratio", | ||
| "image-redundant-alt", | ||
| "image-size-responsive", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit concerned with this diff... but I also don't fully grasp what this step is doing.
It seems image-size-responsive has been removed from the snapshot?
Is that expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for calling this out.
This snapshot comes from this test, which does a snapshot Lighthouse run.
What happened is related to devtoolsLogs being added as a required artifact. Snapshot runs have no devtoolsLogs, since that's a moment-in-time and that artifact does not support snapshot mode. So this change currently omits this audit from running. Since it's an optional enhancement, that is unfortunate.
The fix is to place devtoolsLogs in meta.__internalOptionalArtifacts instead, and then only use it / create NetworkRecords if present on artifacts.
|
Cool - I merged, linted, and updated the sample json. I didn't do anything with the snapshot comments above... is that needed as well? Hopefully this little fix isn't becoming a pain - I figured it was an easy patch!! 😃 |
|
Alright - I see the CI failed due to the missing audit test. |
|
Ok, that was an easy add to the code. __internalOptionalArtifacts + checks for missing devtoolsLogs However, the devtoolsLogs are now consistently undefined when running the CLI. I found this comment that seems to suggest exactly what I'm seeing lighthouse/core/audits/dobetterweb/dom-size.js Lines 85 to 94 in cd200f4
|
|
I think I have a working fix!
Sweet. I'll convert, test, and re-commit later today. |
devtoolsLogs wasn't loading as optional. But, found a reference in the changelogs indicating DevtoolsLog is preferred. Testing shows DevtoolsLog is available in navigation mode.
The image-size-responsive test was added back in.
|
I think this commit will pass the CI |
|
Thanks for the improvement, and for sticking through the additional changes! |

Summary
bugfix
The current audit relies on guessing MimeType based on file extension. This can lead to inaccurate results for dynamically generated files since file extension is not guaranteed. This commit retrieves the real mimeType, while preserving the existing guess approach as a fallback.
This change will be transparent for existing SVG images, and only improves handling of images claiming to be SVG with alternate file extensions.
Unit tests have also been updated to accommodate the async audit, and simulated network records.
Thanks!!
Related Issues/PRs
Fixes #12018