Skip to content
Snippets Groups Projects
Commit 752caffd authored by RMidhunSuresh's avatar RMidhunSuresh
Browse files

Hide UI on error

parent d191f966
No related branches found
No related tags found
No related merge requests found
...@@ -34,6 +34,7 @@ function shouldStartMinimized(): boolean { ...@@ -34,6 +34,7 @@ function shouldStartMinimized(): boolean {
} }
async function main() { async function main() {
hideOnError();
const root = document.querySelector(rootDivId) as HTMLDivElement; const root = document.querySelector(rootDivId) as HTMLDivElement;
if (!root) { if (!root) {
throw new Error("No element with id as 'chatterbox' found!"); throw new Error("No element with id as 'chatterbox' found!");
...@@ -61,6 +62,24 @@ function allowsChild(parent, child) { ...@@ -61,6 +62,24 @@ function allowsChild(parent, child) {
} }
} }
function hideOnError() {
// When an error occurs, log it and then hide everything!
const handler = e => {
if (e.message === "ResizeObserver loop completed with undelivered notifications." ||
e.message === "ResizeObserver loop limit exceeded") {
// see https://stackoverflow.com/a/64257593
e.stopImmediatePropagation();
return false;
}
console.error(e.error ?? e.reason);
(window as any).sendError();
return false;
};
window.addEventListener("error", handler, true);
window.addEventListener("unhandledrejection", handler, true);
}
(window as any).sendViewChangeToParent = function (view: "timeline" | "account-setup") { (window as any).sendViewChangeToParent = function (view: "timeline" | "account-setup") {
window.parent?.postMessage({ window.parent?.postMessage({
action: "resize-iframe", action: "resize-iframe",
...@@ -76,4 +95,8 @@ function allowsChild(parent, child) { ...@@ -76,4 +95,8 @@ function allowsChild(parent, child) {
window.parent?.postMessage({ action: "unread-message", count }, "*"); window.parent?.postMessage({ action: "unread-message", count }, "*");
}; };
(window as any).sendError = function () {
window.parent?.postMessage({ action: "error" }, "*");
};
main(); main();
...@@ -42,3 +42,10 @@ export function resizeIframe(data) { ...@@ -42,3 +42,10 @@ export function resizeIframe(data) {
if (height) { iframeElement.style.height = height; } if (height) { iframeElement.style.height = height; }
if (width) { iframeElement.style.width = width; } if (width) { iframeElement.style.width = width; }
} }
export function removeIframe() {
const iframeElement = document.querySelector(".chatterbox-iframe") as HTMLIFrameElement;
iframeElement?.remove();
const startButton = document.querySelector(".start") as HTMLDivElement;
startButton.remove();
}
import { resizeIframe, toggleIframe } from "./iframe"; import { resizeIframe, toggleIframe, removeIframe } from "./iframe";
import { loadStartButton } from "./load"; import { loadStartButton } from "./load";
import "./parent-style.css"; import "./parent-style.css";
...@@ -33,6 +33,9 @@ window.addEventListener("message", event => { ...@@ -33,6 +33,9 @@ window.addEventListener("message", event => {
case "unread-message": case "unread-message":
setUnreadCount(event.data.count); setUnreadCount(event.data.count);
break; break;
case "error":
removeIframe();
break;
} }
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment