How to inline dynamically generated manifest.json documents with standard JavaScript
I included the following link rel like this one in the html header, WITHOUT a valid href property, yet:
link rel="manifest" id="my-manifest-placeholder"
(see also "How to Setup Your Web App Manifest Dynamically Using Javascript" https://medium.com/@alshakero/how-to-setup-your-web-app-manifest-dynamically-using-javascript-f7fbee899a61 which unfortunately did NOT work for me!)
(or "Inline Web App Manifest", Inline the Web App Manifest? which inspired my solution very much)
Later, I ran the following javascript:
thisHostUrl = "http://localhost/";
// json manifest, escaped as a string
var myManifest = '{\"short_name\": \"ungravel\",\"name\": \"Ungravel:%20Cofounder%20GroupWallet\",\"icons\": [{\"src\": \"' + thisHostUrl + 'icon192x192.png\",\"type\": \"image\/png\",\"sizes\": \"192x192\",\"purpose\": \"any%20maskable\"},{\"src\": \"' + thisHostUrl + 'icon512x512.png\",\"type\": \"image\/png\",\"sizes\": \"512x512\",\"purpose\": \"any%20maskable\"}],\"start_url\": \"' + thisHostUrl + '\",\"background_color\": \"rgb(225,230,233)\",\"display_override\": [\"window-control-overlay\", \"standalone\"],\"display\": \"fullscreen\",\"orientation\": \"landscape-primary\",\"scope\": \"' + thisHostUrl + '\",\"theme_color\": \"rgb(179,231,253)\",\"shortcuts\": [{\"name\": \"Ungravel:%20Cofounder%20GroupWallet\",\"short_name\": \"ungravel\",\"description\": \"Create%20co-founder%20group%20with%20shares%20and%20GroupWallet\",\"url\": \"' + thisHostUrl + '\",\"icons\": [{ \"src\": \"' + thisHostUrl + 'icon64x64.png\", \"sizes\": \"64x64\", \"type\": \"image\/png\" }, { \"src\": \"' + thisHostUrl + 'icon192x192.png\", \"sizes\": \"192x192\", \"type\": \"image\/png\"}]}],\"description\": \"Co-found%20a%20distributed%20group%20on%20ethereum%20blockchain,%20based%20on%20ERC20-compatible%20GroupToken%20shares%20and%20NameRegistry%20NFTs%20(ENS)\",\"screenshots\": [{\"src\": \"' + thisHostUrl + 'screenshot1.jpg\",\"type\": \"image\/jpg\",\"sizes\": \"842x790\"},{\"src\": \"' + thisHostUrl + 'screenshot2.jpg\",\"type\": \"image\/jpg\",\"sizes\": \"1144x630\"}]}';
const stringManifest = 'data:application/manifest+json,'+myManifest;
document.querySelector('#my-manifest-placeholder').setAttribute('href', stringManifest);
DO NOT forget to escape spaces and special chars, such as / and "".
https://www.tutorialspoint.com/json_simple/json_simple_escape_characters.htm
Be aware of the color codes for background and themeColors: rgb(179,231,253)
DO NOT use hex colors or escape the #-special char.
I tried URL.createObjectURL(xxxxx), but the dynamically href is happy with:
data:application/manifest+json + the dynamically generated manifest, in my case myManifest
Google Version 91.0.4472.77 (Offizieller Build) (x86_64) loads the manifest from my source without any extra network access, thus saving network requests for my single-page PWA. A bit ugly, but it works.
Since the manifest format is yet final and still in development, I assume, properties may change and this solution may NOT work in other Google Chrome browsers.