Skip to content
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

Merged
merged 15 commits into from
May 7, 2019
Merged

audit: add apple-touch-icon audit #8857

merged 15 commits into from
May 7, 2019

Conversation

exterkamp
Copy link
Member

Summary
Adds a new audit to the PWA category to check for apple-touch-icon link for iOS installability.

Related Issues/PRs
fixes: #7890

@@ -1100,7 +1108,7 @@
"name": "WordPress"
}
],
"summary": {},
"summary": null,
Copy link
Member Author

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?

Copy link
Member

@brendankenny brendankenny May 5, 2019

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?

Copy link
Member Author

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 🤔

Copy link
Member Author

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.

Copy link
Collaborator

@connorjclark connorjclark May 5, 2019

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

Copy link
Member

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

Copy link
Member

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 :)

Copy link
Member Author

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.';
Copy link
Member Author

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',
Copy link
Member Author

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.

Copy link
Collaborator

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i18n'd! 🇮🇨

Copy link
Collaborator

@patrickhulce patrickhulce left a 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 😁

lighthouse-core/test/audits/ios-pwa-icon-test.js Outdated Show resolved Hide resolved
lighthouse-core/audits/ios-pwa-icon.js Outdated Show resolved Hide resolved
lighthouse-core/audits/ios-pwa-icon.js Outdated Show resolved Hide resolved
const appleTouchIcons = artifacts.LinkElements.filter(el => el.rel === 'apple-touch-icon');

// Audit passes if an `apple-touch-icon` exists.
const passed = appleTouchIcons.length !== 0;
Copy link
Collaborator

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?

Copy link
Member Author

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.

Copy link
Member

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',
Copy link
Collaborator

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?

lighthouse-core/config/default-config.js Outdated Show resolved Hide resolved
@exterkamp exterkamp marked this pull request as ready for review May 5, 2019 02:03
@exterkamp exterkamp requested a review from paulirish as a code owner May 5, 2019 02:03
@exterkamp
Copy link
Member Author

Reading the docs more:

  • You can include a startup image as well <link rel="apple-touch-startup-image" href="/launch.png">
  • You can specify a launch icon title with the <title> or <meta name="apple-mobile-web-app-title" content="AppTitle">

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.

@paulirish
Copy link
Member

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. :)

Copy link
Member

@brendankenny brendankenny left a 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

lighthouse-core/audits/ios-pwa-icon.js Outdated Show resolved Hide resolved
lighthouse-core/audits/ios-pwa-icon.js Outdated Show resolved Hide resolved
lighthouse-core/audits/ios-pwa-icon.js Outdated Show resolved Hide resolved
lighthouse-core/audits/ios-pwa-icon.js Outdated Show resolved Hide resolved
lighthouse-core/audits/ios-pwa-icon.js Outdated Show resolved Hide resolved
lighthouse-core/audits/ios-pwa-icon.js Outdated Show resolved Hide resolved
*/
static audit(artifacts, _) {
const appleTouchIcons = artifacts.LinkElements.filter(
el => el.rel === 'apple-touch-icon' && el.href !== undefined);
Copy link
Member

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;
Copy link
Member

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.

lighthouse-core/audits/ios-pwa-icon.js Outdated Show resolved Hide resolved
@@ -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'},
Copy link
Member

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

lighthouse-core/audits/ios-pwa-icon.js Outdated Show resolved Hide resolved
lighthouse-core/audits/ios-pwa-icon.js Outdated Show resolved Hide resolved
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).',
Copy link
Member

@paulirish paulirish May 5, 2019

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.

Copy link
Member Author

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

Copy link
Collaborator

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

lighthouse-core/audits/ios-pwa-icon.js Outdated Show resolved Hide resolved
'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.',
Copy link
Member

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.

Copy link
Member Author

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);
Copy link
Member

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

  1. 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.
  2. 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.

Copy link
Member Author

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.

lighthouse-core/audits/ios-pwa-icon.js Outdated Show resolved Hide resolved
@paulirish paulirish added the P0 label May 5, 2019
Copy link
Member

@brendankenny brendankenny left a 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
Copy link
Member

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)

Copy link
Member Author

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....

Copy link
Member Author

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.

@@ -1100,7 +1108,7 @@
"name": "WordPress"
}
],
"summary": {},
"summary": null,
Copy link
Member

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 :)

@exterkamp
Copy link
Member Author

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.

Copy link
Member

@paulirish paulirish left a 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 => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.filter(el => !!el.href)

Copy link
Member Author

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);

Copy link
Member

@brendankenny brendankenny May 6, 2019

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OHHHHHHHH got it.

Copy link
Member

@paulirish paulirish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high level lgtm

lighthouse-cli/test/smokehouse/pwa-expectations.js Outdated Show resolved Hide resolved
lighthouse-core/audits/apple-touch-icon.js Outdated Show resolved Hide resolved
|| !el.href) {
const appleTouchIcons = artifacts.LinkElements
.filter(el => el.rel === 'apple-touch-icon' || el.rel === 'apple-touch-icon-precomposed')
.filter(el => {
Copy link
Member

@brendankenny brendankenny May 6, 2019

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.

lighthouse-core/audits/apple-touch-icon.js Outdated Show resolved Hide resolved
lighthouse-core/audits/apple-touch-icon.js Outdated Show resolved Hide resolved
lighthouse-core/audits/apple-touch-icon.js Outdated Show resolved Hide resolved
Copy link
Member

@brendankenny brendankenny left a 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)

@exterkamp exterkamp changed the title audit: add iOS pwa icon audit audit: add apple-touch-icon audit May 6, 2019
…d before? Removed href explanation. Updated en-US.
@paulirish
Copy link
Member

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 :)

lighthouse-core/audits/apple-touch-icon.js Outdated Show resolved Hide resolved
lighthouse-core/audits/apple-touch-icon.js Outdated Show resolved Hide resolved
lighthouse-core/audits/apple-touch-icon.js Outdated Show resolved Hide resolved
lighthouse-core/audits/apple-touch-icon.js Outdated Show resolved Hide resolved
lighthouse-core/audits/apple-touch-icon.js Outdated Show resolved Hide resolved
lighthouse-core/test/audits/apple-touch-icon-test.js Outdated Show resolved Hide resolved
lighthouse-core/test/audits/apple-touch-icon-test.js Outdated Show resolved Hide resolved
lighthouse-core/audits/apple-touch-icon.js Outdated Show resolved Hide resolved
lighthouse-core/audits/apple-touch-icon.js Outdated Show resolved Hide resolved
Copy link
Member

@brendankenny brendankenny left a 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

@brendankenny brendankenny merged commit acfa777 into master May 7, 2019
@brendankenny brendankenny deleted the ios-pwa branch May 7, 2019 00:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Include apple-touch-icon in PWA icon requirements
5 participants