Skip to content

Instantly share code, notes, and snippets.

@rviscomi
Created May 12, 2021 03:59
Show Gist options
  • Save rviscomi/70d588cf8643dce4fb55050388fca836 to your computer and use it in GitHub Desktop.
Save rviscomi/70d588cf8643dce4fb55050388fca836 to your computer and use it in GitHub Desktop.
WebPageTest custom metric: web app manifest
[web-app-manifest]
const response_bodies = $WPT_BODIES;
const manifestURLs = new Set(Array.from(document.querySelectorAll('link[rel=manifest]')).map(link => {
const base = new URL(location.href).origin;
const href = link.getAttribute('href');
return new URL(href, base).href;
}));
const manifests = response_bodies.filter(har => {
return manifestURLs.has(har.url);
}).map(har => {
let manifest;
try {
manifest = JSON.parse(har.response_body);
} catch (e) {
manifest = har.response_body;
}
return [har.url, manifest];
});
return JSON.stringify(Object.fromEntries(manifests), null, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment