Skip to content

Latest commit

 

History

History
34 lines (30 loc) · 909 Bytes

web-app-manifest.md

File metadata and controls

34 lines (30 loc) · 909 Bytes
tags layout title description contributedBy
customMetrics
layouts/code-example.njk
Web App Manifest Contents
Retrieve the web app manifest for the page and output the manifest URL and contents in JSON format
name url
Rick Viscomi
[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);