-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
audit: add apple-touch-icon audit #8857
Conversation
proto/sample_v2_round_trip.json
Outdated
@@ -1100,7 +1108,7 @@ | |||
"name": "WordPress" | |||
} | |||
], | |||
"summary": {}, | |||
"summary": null, |
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.
Does this need to be fixed seperately? Not handled by #8605?
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.
Not handled by #8605?
Nope
Does this need to be fixed seperately?
You tell me :) Why did it change these unrelated ones?
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.
Just did it on master, same thing. I'm not 100% sure why. It is converting {}
into null
inside of detail elements. I'm not overly concerned with it, since its a conversion difference within details
. I can look more into it. I think it has to do with #8605 somehow tho 🤔
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.
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.
@exterkamp maybe we should assert on proto --version
in compile-proto. #8863
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.
Found it. In #8539 it was changed (I think in error) and I think it is supposed to be
null
.
nice catch. One issue is that the details
roundtrip check is using toMatchObject
, which while also helpful here, will also happily assert true for expect({summary: null}).toMatchObject({summary: {}})
or expect({summary:{}}).toMatchObject({summary: {}})
Is it supposed to be null
, though? It's {}
in sample_v2.json
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.
after #8867, these will need to be {}
. Update to > 3.7.1 to get that automatically :)
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 upgraded to 3.7.1 and its still null
...
|
||
let explanation; | ||
if (!passed) { | ||
explanation = 'No `apple-touch-icon` link found.'; |
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.
Wording?
static get meta() { | ||
return { | ||
id: 'ios-pwa-icon', | ||
title: 'Web app has a valid iOS touch icon', |
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.
Open for wording nits on title
, failureTitle
, and description
.
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.
Seems fine to me! Though not sure if we should move away from "Web app" as the noun? Still see folks benefit if they dont consider themselves an app
I18n these?
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.
i18n'd! 🇮🇨
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.
Nice!! I'm def on board for this for 5 😁
const appleTouchIcons = artifacts.LinkElements.filter(el => el.rel === 'apple-touch-icon'); | ||
|
||
// Audit passes if an `apple-touch-icon` exists. | ||
const passed = appleTouchIcons.length !== 0; |
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.
Probably cant do much without fetching the icon but at least make sure it has an href or something? Does it have to be on same origin or any other requirement?
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.
Added href existence check, I don't think there are any origin requirements.
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.
maybe also a valid href? Can do new URL(el.href, artifacts.URL.finalUrl)
(finalUrl
to handle the relative URL) in a try catch to check that it's valid. Kind of dumb but an easy check to add.
static get meta() { | ||
return { | ||
id: 'ios-pwa-icon', | ||
title: 'Web app has a valid iOS touch icon', |
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.
Seems fine to me! Though not sure if we should move away from "Web app" as the noun? Still see folks benefit if they dont consider themselves an app
I18n these?
Reading the docs more:
Don't know if we want to include more optional-ish things like this in a more generic iOS PWA health audit, or more iOS specific PWA audits like this one. |
In the future, perhaps. But not in this sprint. :) |
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.
nice! thanks for taking this on
*/ | ||
static audit(artifacts, _) { | ||
const appleTouchIcons = artifacts.LinkElements.filter( | ||
el => el.rel === 'apple-touch-icon' && el.href !== undefined); |
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.
some sources seem to indicate it only these if in the <head>
(so would also need to check el.source === 'head'
), but I can't find a definitive answer on that yet
const appleTouchIcons = artifacts.LinkElements.filter(el => el.rel === 'apple-touch-icon'); | ||
|
||
// Audit passes if an `apple-touch-icon` exists. | ||
const passed = appleTouchIcons.length !== 0; |
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.
maybe also a valid href? Can do new URL(el.href, artifacts.URL.finalUrl)
(finalUrl
to handle the relative URL) in a try catch to check that it's valid. Kind of dumb but an easy check to add.
@@ -516,6 +517,7 @@ const defaultConfig = { | |||
{id: 'is-on-https', weight: 2, group: 'pwa-installable'}, | |||
{id: 'service-worker', weight: 1, group: 'pwa-installable'}, | |||
{id: 'installable-manifest', weight: 2, group: 'pwa-installable'}, | |||
{id: 'ios-pwa-icon', weight: 1, group: 'pwa-installable'}, |
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.
as above, I don't believe this is required for installability (though we should check). Would be pwa-optimized
group in that case.
We also have talked about making the current group "Chrome installable" and having separate groups for Firefox, Safari, etc as we add them so we don't end up with a mixed browser checklist, which can be kind of confusing when testing. We should revisit that decision before (if) adding it to the current installable list
description: | ||
'In order to be installable as an iOS PWA ' + | ||
'sites must have a valid apple-touch-icon. ' + | ||
'[Learn More](https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/ConfiguringWebApplications.html).', |
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.
wild idea. let's link to https://webhint.io/docs/user-guide/hints/hint-apple-touch-icons/ for now. tbh it's the best resource i can find, by far.
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 like brendan's developers.goog link
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.
as a wise man once told me, s/crazy idea/ 💭/
😉
anyhoo, while the webhint docs do an awesome job explaining, I think it might be confusing to see the "what passes what fails" section of a different tool that isn't guaranteed to be in sync with the Lighthouse version they're coming from
'sites must have a valid apple-touch-icon. ' + | ||
'[Learn More](https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/ConfiguringWebApplications.html).', | ||
/** Explanatory message stating that there was a failure in an audit caused by the page having an invalid apple-touch-icon link. `apple-touch-icon` is a HTML tag value and should not be translated. */ | ||
explanation: 'No valid `apple-touch-icon` link found.', |
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.
IMO we can leave out an explanation. i know other PWA audits have them but it's just repeating the title here.
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.
Good call.
Made an href explanation for the new href checks failing.
*/ | ||
static audit(artifacts, _) { | ||
const appleTouchIcons = artifacts.LinkElements.filter( | ||
el => el.rel === 'apple-touch-icon' && el.href !== undefined); |
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.
there's 2 extra checks here that could make sense
- they don't provide the [sizes] attribute (on at least one of them).
- see
view-source:https://caltrainschedule.io/
for an example - this gets a little tricky in our UX so i think we punt for today.
- see
apple-touch-icon-precomposed
is basically equivalent.- a bunch of PWAs including https://jakearchibald.github.io/svgomg/ use this instead of the original.
- It's basically not necessary these days, but i think we should allow this
rel
for now. later we can add a warning that it should be changed.
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.
Added 2. with a warning.
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.
one big thing I forgot, need to add these to the smoke test expectations for the pwa
, pwa2
, and pwa3
smoke tests.
I usually just let the smoke test do the investigation for each site by adding an entry for the audit in the expectations file that's obviously wrong, run the smoke test, and if the actual
that gets printed looks good, I add that to the expectations file.
If we're going to have a warning and stuff, would be good to capture that for those real sites that have them
new URL(el.href); | ||
return true; | ||
} catch (e) {} | ||
// Check if the href needs the base url to be valid |
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.
you can just combine these checks (the base url is ignored if the first argument is already absolute)
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.
It doesn't seeeeeem like that works....
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.
got it! finalUrl was undefined, and was silently throwing and caught by the audit.
proto/sample_v2_round_trip.json
Outdated
@@ -1100,7 +1108,7 @@ | |||
"name": "WordPress" | |||
} | |||
], | |||
"summary": {}, | |||
"summary": null, |
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.
after #8867, these will need to be {}
. Update to > 3.7.1 to get that automatically :)
Got the base_url working. It was that the artifacts.URL.finalUrl was undefined in the tests. This seems like a fragile test for valid href's though, since the only way it will fail is if the href is invalid AND the final Url is invalid, as in the test. If either are valid, then it passes. |
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.
potentially fetching the url to see if it's a valid icon
fetching is a bag of worms, so let's save that till later.
|| !el.href) { | ||
const appleTouchIcons = artifacts.LinkElements | ||
.filter(el => el.rel === 'apple-touch-icon' || el.rel === 'apple-touch-icon-precomposed') | ||
.filter(el => { |
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.
.filter(el => !!el.href)
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.
then el.href is string | null
and would need to be el.href || ''
to make ts be quiet. How do I make ts love me?
// Check that the href is valid
try {
new URL(el.href, artifacts.URL.finalUrl);
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 think @paulirish was building on the point @patrickhulce made, which is that LinkElements
already did this check (sorry, I had forgotten). If el.href
exists, the URL is valid. so only need to do .filter(el => !!el.href)
for this entire block of stuff.
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.
OHHHHHHHH got it.
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.
high level lgtm
|| !el.href) { | ||
const appleTouchIcons = artifacts.LinkElements | ||
.filter(el => el.rel === 'apple-touch-icon' || el.rel === 'apple-touch-icon-precomposed') | ||
.filter(el => { |
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 think @paulirish was building on the point @patrickhulce made, which is that LinkElements
already did this check (sorry, I had forgotten). If el.href
exists, the URL is valid. so only need to do .filter(el => !!el.href)
for this entire block of stuff.
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.
(switching review status for bookkeeping)
…d before? Removed href explanation. Updated en-US.
FYI i put in a PR at google/WebFundamentals#7582 to update the WF article we link to. Happy for upgrades there. I was doing the bare minimum :) |
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!
Thanks for taking this @exterkamp
Summary
Adds a new audit to the PWA category to check for apple-touch-icon link for iOS installability.
Related Issues/PRs
fixes: #7890