From dc781da93a271d4040df61281d8524b50e099a0d Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Thu, 1 Jul 2021 09:27:02 +0200 Subject: [PATCH] Use ES5 build for Supervisor on Safari 12 and below (#9485) --- build-scripts/gulp/entry-html.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/build-scripts/gulp/entry-html.js b/build-scripts/gulp/entry-html.js index eeb1b57ecc..c98b6d6acb 100644 --- a/build-scripts/gulp/entry-html.js +++ b/build-scripts/gulp/entry-html.js @@ -302,15 +302,23 @@ gulp.task("gen-index-hassio-prod", async () => { function writeHassioEntrypoint(latestEntrypoint, es5Entrypoint) { fs.mkdirSync(paths.hassio_output_root, { recursive: true }); + // Safari 12 and below does not have a compliant ES2015 implementation of template literals, so we ship ES5 fs.writeFileSync( path.resolve(paths.hassio_output_root, "entrypoint.js"), ` -try { - new Function("import('${latestEntrypoint}')")(); -} catch (err) { +function loadES5() { var el = document.createElement('script'); el.src = '${es5Entrypoint}'; document.body.appendChild(el); +} +if (/.*Version\/(?:11|12)(?:\.\d+)*.*Safari\//.test(navigator.userAgent)) { + loadES5(); +} else { + try { + new Function("import('${latestEntrypoint}')")(); + } catch (err) { + loadES5(); + } } `, { encoding: "utf-8" }