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
report: handle invalid urls for source location items #11299
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
@googlebot I signed it! |
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
@adrianaixba you may wish to set your email for the Lighthouse repo (and all google git repos) to your google email: |
it('renders source-location with lh-link class for invalid urls', () => { | ||
const sourceLocation = { | ||
type: 'source-location', | ||
url: 'invalid-url://www.example.com/script.js', |
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.
renderSourceLocation
errors when _renderLink
fails to create an anchor element, which only happens if item.url
is an ill-formed URL or one of invalid protocol.
However, I'm having trouble understanding when that can happen, because if item.urlProvider === 'network'
, as is the case here, my understanding is that item.url
must always be a valid URL of protocol http
or https
. This is set in just a handful of places [1], and I think each one is certain to come from a network record, thus must be a valid URL.
It's not trivial to see this, and clearly it's wrong as we've gotten an error report, so we should certainly guard against this in the details renderer. But I'd like to see an example of an erroring case so we can be sure that we are testing against the correct "bad url" here.
It'd help to find a reproduction case. I requested the issue filer to provide one #11261
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.
We found the error'ing url to be a relative url, like /url/main.js
. Can you update the "invalid url" in this test to be that?
I'd also suggest a truly invalid url, one that would throw an error for new URL()
, like new URL('atx')
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 helped with finding a renderer-side solution here, so i'm biased. but this lgtm. 👍
agree that there's extra work to harden the internals so this won't happen. #11261 (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.
LGTM!
For #11261
Adds lh-link class to source-location render element. Needed to handle invalid URLs that didn’t create elements.