From ee53e70929533ee5abd9d6aa7529a21cf9573cb9 Mon Sep 17 00:00:00 2001 From: Sam Thorogood Date: Tue, 29 May 2018 11:33:01 +1000 Subject: [PATCH] send credentials if requested --- pwacompat.js | 19 +++++++++++++------ pwacompat.min.js | 14 +++++++------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/pwacompat.js b/pwacompat.js index 2988204..9c89773 100644 --- a/pwacompat.js +++ b/pwacompat.js @@ -18,11 +18,7 @@ (function() { if (!('fetch' in window)) { - return; - } else if (document.readyState === 'complete') { - setup(); - } else { - window.addEventListener('load', setup); + return; // basic feature detection: from Mobile Safari 10.3+ } const capableDisplayModes = ['standalone', 'fullscreen', 'minimal-ui']; @@ -44,7 +40,11 @@ if (!manifestHref) { throw `can't find '`; } - return window.fetch(manifestHref); + const opts = /** @type {!RequestInit} */ ({}); + if (manifestHref.crossOrigin === 'use-credentials') { + opts.credentials = 'include'; + } + return window.fetch(manifestHref, opts); }) .then((response) => response.json()) .then((data) => process(data, manifestHref)) @@ -252,4 +252,11 @@ canvas.height = height; return canvas.getContext('2d'); } + + // actually run PWACompat here + if (document.readyState === 'complete') { + setup(); + } else { + window.addEventListener('load', setup); + } }()); diff --git a/pwacompat.min.js b/pwacompat.min.js index 7a2541d..4527a56 100644 --- a/pwacompat.min.js +++ b/pwacompat.min.js @@ -1,7 +1,7 @@ -(function(){function l(){var a=document.head.querySelector('link[rel="manifest"]'),b=a?a.href:"";Promise.resolve().then(function(){if(!b)throw'can\'t find \'';return window.fetch(b)}).then(function(a){return a.json()}).then(function(a){return n(a,b)}).catch(function(a){return console.warn("pwacompat.js error",a)})}function p(a,b){a=document.createElement(a);for(var c in b)a.setAttribute(c,b[c]);document.head.appendChild(a);return a}function h(a,b){b&&(!0===b&&(b="yes"), -p("meta",{name:a,content:b}))}function n(a,b){function c(e,c,b){var d=e.width,g=e.height,f=window.devicePixelRatio;e=q({width:d*f,height:g*f});e.scale(f,f);e.fillStyle=a.background_color||"#f8f9fa";e.fillRect(0,0,d,g);e.translate(d/2,(g-32)/2);e.font="24px HelveticaNeue-CondensedBold";e.fillStyle=l?"white":"black";d=e.measureText(r).width;b&&(g=b.width/f,f=b.height/f,128a?a/12.92:Math.pow((a+.055)/1.055,2.4)});return 3\'';var a={};"use-credentials"===b.crossOrigin&&(a.credentials="include");return window.fetch(b,a)}).then(function(a){return a.json()}).then(function(a){return n(a,b)}).catch(function(a){return console.warn("pwacompat.js error",a)})}function p(a,b){a=document.createElement(a);for(var c in b)a.setAttribute(c,b[c]); +document.head.appendChild(a);return a}function h(a,b){b&&(!0===b&&(b="yes"),p("meta",{name:a,content:b}))}function n(a,b){function c(e,c,b){var d=e.width,g=e.height,f=window.devicePixelRatio;e=q({width:d*f,height:g*f});e.scale(f,f);e.fillStyle=a.background_color||"#f8f9fa";e.fillRect(0,0,d,g);e.translate(d/2,(g-32)/2);e.font="24px HelveticaNeue-CondensedBold";e.fillStyle=l?"white":"black";d=e.measureText(r).width;b&&(g=b.width/f,f=b.height/f,128a?a/12.92:Math.pow((a+.055)/1.055,2.4)});return 3