Skip to content

Commit

Permalink
core(installability-errors): add url scheme error (#13846)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamraine committed Apr 13, 2022
1 parent e1beeb1 commit 9ca3d1c
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lighthouse-core/audits/installable-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ const UIStrings = {
'protocol-timeout': `Lighthouse could not determine if there was a service worker. Please try with a newer version of Chrome.`,
/** Message logged when the web app has been uninstalled o desktop, signalling that the install banner state is being reset. */
'pipeline-restarted': 'PWA has been uninstalled and installability checks resetting.',
/**
* @description Error message explaining that the URL of the manifest uses a scheme that is not supported on Android.
* @example {data:} scheme
*/
'scheme-not-supported-for-webapk': 'The manifest URL scheme ({scheme}) is not supported on Android.',
};
/* eslint-enable max-len */

Expand Down Expand Up @@ -156,6 +161,17 @@ class InstallableManifest extends Audit {
// @ts-expect-error errorIds from protocol should match up against the strings dict
const matchingString = UIStrings[err.errorId];

if (err.errorId === 'scheme-not-supported-for-webapk') {
// If there was no manifest, then there will be at lest one other installability error.
// We can ignore this error if that's the case.
const manifestUrl = artifacts.WebAppManifest?.url;
if (!manifestUrl) continue;

const scheme = new URL(manifestUrl).protocol;
i18nErrors.push(str_(matchingString, {scheme}));
continue;
}

// Handle an errorId we don't recognize.
if (matchingString === undefined) {
i18nErrors.push(str_(UIStrings.noErrorId, {errorId: err.errorId}));
Expand Down
33 changes: 33 additions & 0 deletions lighthouse-core/test/audits/installable-manifest-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,39 @@ describe('PWA: webapp install banner audit', () => {
assert.strictEqual(result.score, 1);
});
});

it('adds scheme to invalid scheme error message', async () => {
const artifacts = generateMockArtifacts();
artifacts.WebAppManifest.url = 'data:application/json;base64,AAAAAAAAAA';
artifacts.InstallabilityErrors.errors.push({
errorId: 'scheme-not-supported-for-webapk',
errorArguments: [],
});
const context = generateMockAuditContext();

const result = await InstallableManifestAudit.audit(artifacts, context);
expect(result.score).toEqual(0);
expect(result.details.items[0].reason).toBeDisplayString(
'The manifest URL scheme (data:) is not supported on Android.'
);
});

it('ignores invalid scheme error if there was no manifest url', async () => {
const artifacts = generateMockArtifacts();
artifacts.WebAppManifest = undefined;
artifacts.InstallabilityErrors.errors.push(
{errorId: 'no-manifest', errorArguments: []},
{errorId: 'scheme-not-supported-for-webapk', errorArguments: []}
);
const context = generateMockAuditContext();

const result = await InstallableManifestAudit.audit(artifacts, context);
expect(result.score).toEqual(0);
expect(result.details.items).toHaveLength(1);
expect(result.details.items[0].reason).toBeDisplayString(
'Page has no manifest <link> URL'
);
});
});

describe('warnings', () => {
Expand Down
3 changes: 3 additions & 0 deletions shared/localization/locales/en-US.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions shared/localization/locales/en-XL.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Array [
"platform-not-supported-on-android",
"prefer-related-applications",
"prefer-related-applications-only-beta-stable",
"scheme-not-supported-for-webapk",
"start-url-not-valid",
"url-not-supported-for-webapk",
"warn-not-offline-capable",
Expand Down

0 comments on commit 9ca3d1c

Please sign in to comment.