-
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
core(installable-manifest): check for fetchable icon #10168
Changes from 4 commits
a1967d2
9286bac
8e23bff
a29fd77
dd3785c
cb119aa
86da15f
d52a99c
cff5ce3
dbc1f42
ae67065
292a3eb
c3e6459
3c36dc4
f0467f9
77b155d
50cc495
2351fc6
a5db32d
276fa39
691ab34
1f9b1d1
e86fc0b
aaedac3
8ed9b9e
533e6c1
5078cab
9d63999
5b2ca74
88fbc8d
f36ef02
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ const NetworkAnalyzer = require('../lib/dependency-graph/simulator/network-analy | |
const NetworkRecorder = require('../lib/network-recorder.js'); | ||
const constants = require('../config/constants.js'); | ||
const i18n = require('../lib/i18n/i18n.js'); | ||
const pageFunctions = require('../lib/page-functions.js'); | ||
|
||
/** @typedef {import('../gather/driver.js')} Driver */ | ||
|
||
|
@@ -536,7 +537,24 @@ class GatherRunner { | |
static async getWebAppManifest(passContext) { | ||
const response = await passContext.driver.getAppManifest(); | ||
if (!response) return null; | ||
return manifestParser(response.data, response.url, passContext.url); | ||
const manifest = manifestParser(response.data, response.url, passContext.url); | ||
|
||
// Add a warning for icons that aren't fetchable. | ||
if (manifest.value && Array.isArray(manifest.value.icons.value)) { | ||
const iconsToFetch = manifest.value.icons.value | ||
.filter(icon => icon.value.src && icon.value.src.value); | ||
const fetchPromises = iconsToFetch.map(async icon => { | ||
const expression = `(${pageFunctions.fetchIsOkString})( | ||
${JSON.stringify(icon.value.src.value)} | ||
)`; | ||
if (!await passContext.driver.evaluateAsync(expression, {useIsolation: true})) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feels like we should make this timeout very short and |
||
icon.warning = 'Error fetching icon'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't love the Promise.all mutating an object, can we make this a map of the icon results? |
||
} | ||
}); | ||
await Promise.all(fetchPromises); | ||
} | ||
|
||
return manifest; | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,17 @@ describe('Icons helper', () => { | |
assert.equal(icons.doExist(manifest.value), false); | ||
}); | ||
|
||
it('fails when a manifest contains no fetchable icons', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ooo ooo can we get an empty string test in here before we forget about it again :D |
||
const manifestSrc = JSON.stringify({ | ||
icons: [{ | ||
src: 'icon.png', | ||
}], | ||
}); | ||
const manifest = manifestParser(manifestSrc, EXAMPLE_MANIFEST_URL, EXAMPLE_DOC_URL); | ||
manifest.value.icons.value[0].warning = 'Error fetching icon'; | ||
assert.equal(icons.doExist(manifest.value), false); | ||
}); | ||
|
||
it('succeed when a manifest contains icons', () => { | ||
const manifestSrc = JSON.stringify({ | ||
icons: [{ | ||
|
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.
were empty string icons treated as acceptable before but now they won't be? or I suppose they will be valid because we won't try to fetch and put any warning on them?
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.
at this point empty strings were converted to
undefined
(see parser). later, the icons check will ignore icons whosesrc
does not end in.png
.... however I've just noticed there's a bug if
typeHint === 'image/png'
andsrc
is undefined. this is so dirty. Can fix by tweakinggetFetchableIcons
to also check for a nonempty string.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.
aight sgtm