From ddef201424494f7269d998718e7530737b32e04e Mon Sep 17 00:00:00 2001 From: Krzysztof Date: Tue, 29 Oct 2024 13:29:15 +0100 Subject: [PATCH 1/2] Handle DOM storage being unavailable --- .../src/kbn_bootstrap.ts | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/packages/core/root/core-root-browser-internal/src/kbn_bootstrap.ts b/packages/core/root/core-root-browser-internal/src/kbn_bootstrap.ts index 80020b79427f5..d715b566e7ecd 100644 --- a/packages/core/root/core-root-browser-internal/src/kbn_bootstrap.ts +++ b/packages/core/root/core-root-browser-internal/src/kbn_bootstrap.ts @@ -39,6 +39,75 @@ export async function __kbnBootstrap__() { }), ]); + const isDomStorageDisabled = () => { + try { + const key = 'kbn_bootstrap_domStorageEnabled'; + sessionStorage.setItem(key, 'true'); + sessionStorage.removeItem(key); + localStorage.setItem(key, 'true'); + localStorage.removeItem(key); + return false; + } catch (e) { + return true; + } + }; + + if (isDomStorageDisabled()) { + const defaultErrorText = + 'Your browser needs to have session storage and local storage enabled.'; + const defaultErrorReload = 'Reload'; + const defaultErrorTitle = 'Elastic did not load properly'; + const errorText = i18nError + ? defaultErrorText + : i18n.translate('core.ui.domStorageDisabled', { + defaultMessage: defaultErrorText, + }); + + const errorReload = i18nError + ? defaultErrorReload + : i18n.translate('core.ui.welcomeErrorReloadButton', { + defaultMessage: defaultErrorReload, + }); + const errorTitle = i18nError + ? defaultErrorTitle + : i18n.translate('core.ui.welcomeErrorMessageTitle', { + defaultMessage: defaultErrorTitle, + }); + + const err = document.createElement('div'); + err.style.textAlign = 'center'; + err.style.padding = '120px 20px'; + err.style.fontFamily = 'Inter, BlinkMacSystemFont, Helvetica, Arial, sans-serif'; + + const errorTitleEl = document.createElement('h1'); + errorTitleEl.innerText = errorTitle; + errorTitleEl.style.margin = '20px'; + errorTitleEl.style.color = '#1a1c21'; + + const errorTextEl = document.createElement('p'); + errorTextEl.innerText = errorText; + errorTextEl.style.margin = '20px'; + errorTextEl.style.color = '#343741'; + + const errorReloadEl = document.createElement('button'); + errorReloadEl.innerText = errorReload; + errorReloadEl.onclick = function () { + location.reload(); + }; + errorReloadEl.setAttribute( + 'style', + 'cursor: pointer; padding-inline: 12px; block-size: 40px; font-size: 1rem; line-height: 1.4286rem; border-radius: 6px; min-inline-size: 112px; color: rgb(255, 255, 255); background-color: rgb(0, 119, 204); outline-color: rgb(0, 0, 0); border:none' + ); + + err.appendChild(errorTitleEl); + err.appendChild(errorTextEl); + err.appendChild(errorReloadEl); + + document.body.innerHTML = ''; + document.body.appendChild(err); + return; + } + const coreSystem = new CoreSystem({ injectedMetadata, rootDomElement: document.body, From b9b85cb5f03bd6ff485526c832ee010f78653213 Mon Sep 17 00:00:00 2001 From: Krzysztof Date: Wed, 30 Oct 2024 13:08:46 +0100 Subject: [PATCH 2/2] Update error message --- .../src/kbn_bootstrap.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/core/root/core-root-browser-internal/src/kbn_bootstrap.ts b/packages/core/root/core-root-browser-internal/src/kbn_bootstrap.ts index d715b566e7ecd..a06abd107fd06 100644 --- a/packages/core/root/core-root-browser-internal/src/kbn_bootstrap.ts +++ b/packages/core/root/core-root-browser-internal/src/kbn_bootstrap.ts @@ -53,13 +53,19 @@ export async function __kbnBootstrap__() { }; if (isDomStorageDisabled()) { - const defaultErrorText = - 'Your browser needs to have session storage and local storage enabled.'; + const defaultErrorTitle = `Couldn't load the page`; + const defaultErrorText = `Update your browser's settings to allow storage of cookies and site data, and reload the page.`; const defaultErrorReload = 'Reload'; - const defaultErrorTitle = 'Elastic did not load properly'; + + const errorTitle = i18nError + ? defaultErrorTitle + : i18n.translate('core.ui.welcomeErrorCouldNotLoadPage', { + defaultMessage: defaultErrorTitle, + }); + const errorText = i18nError ? defaultErrorText - : i18n.translate('core.ui.domStorageDisabled', { + : i18n.translate('core.ui.welcomeErrorDomStorageDisabled', { defaultMessage: defaultErrorText, }); @@ -68,11 +74,6 @@ export async function __kbnBootstrap__() { : i18n.translate('core.ui.welcomeErrorReloadButton', { defaultMessage: defaultErrorReload, }); - const errorTitle = i18nError - ? defaultErrorTitle - : i18n.translate('core.ui.welcomeErrorMessageTitle', { - defaultMessage: defaultErrorTitle, - }); const err = document.createElement('div'); err.style.textAlign = 'center';