Skip to content

Commit 97c3049

Browse files
committed
add fallback get request
1 parent 089db69 commit 97c3049

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

Report/index.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -215,17 +215,20 @@ const audit = async (
215215
}
216216

217217
try {
218-
const iconUrls = icons.map(icon => ({
218+
const iconsData = icons.map(icon => ({
219219
src: icon.src,
220220
url: new URL(icon.src, manifestUrl).toString(),
221221
type: icon.type,
222222
sizes: icon.sizes,
223223
}));
224224

225225
const results = await Promise.all(
226-
iconUrls.map(async icon => {
226+
iconsData.map(async icon => {
227227
try {
228-
const res = await fetch(icon.url, { method: 'HEAD' });
228+
let res = await fetch(icon.url, { method: 'HEAD' });
229+
if (!res.ok) {
230+
res = await fetch(icon.url, { method: 'GET' });
231+
}
229232
return {
230233
...icon,
231234
exists: res.ok,
@@ -283,7 +286,7 @@ const audit = async (
283286
}
284287

285288
try {
286-
const screenshotsUrls = screenshots.map(screenshot => ({
289+
const screenshotsData = screenshots.map(screenshot => ({
287290
src: screenshot.src,
288291
url: new URL(screenshot.src, manifestUrl).toString(),
289292
type: screenshot.type,
@@ -292,9 +295,12 @@ const audit = async (
292295
}));
293296

294297
const results = await Promise.all(
295-
screenshotsUrls.map(async screenshot => {
298+
screenshotsData.map(async screenshot => {
296299
try {
297-
const res = await fetch(screenshot.url, { method: 'HEAD' });
300+
let res = await fetch(screenshot.url, { method: 'HEAD' });
301+
if (!res.ok) {
302+
res = await fetch(screenshot.url, { method: 'GET' });
303+
}
298304
return {
299305
...screenshot,
300306
exists: res.ok,
@@ -315,7 +321,7 @@ const audit = async (
315321

316322
const validation: Validation = {
317323
member: 'screenshots',
318-
category: 'recommended',
324+
category: 'required',
319325
displayString: 'Manifest screenshots exist',
320326
errorString: isValid
321327
? ''
@@ -334,7 +340,7 @@ const audit = async (
334340
} catch (error) {
335341
return {
336342
member: 'screenshots',
337-
category: 'recommended',
343+
category: 'required',
338344
displayString: 'Manifest screenshots exist',
339345
errorString: `Error validating screenshots: ${
340346
(error as Error).message
@@ -411,7 +417,6 @@ const audit = async (
411417

412418
if (iconsValidation !== null) {
413419
audits['images-audit'].details.iconsValidation = iconsValidation;
414-
audits['images-audit'].score = iconsValidation?.valid ?? true;
415420
}
416421
if (screenshotsValidation !== null) {
417422
audits['images-audit'].details.screenshotsValidation =
@@ -421,6 +426,8 @@ const audit = async (
421426
audits['images-audit'].score =
422427
(iconsValidation?.valid ?? false) &&
423428
(screenshotsValidation?.valid ?? false);
429+
} else {
430+
audits['images-audit'].score = false
424431
}
425432

426433
return;

0 commit comments

Comments
 (0)