From 06fa9091f4ff4aea8d9c89bf1188d94da2f1323e Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Sun, 1 Aug 2021 14:00:18 +0100 Subject: [PATCH] Allow app preview to handle garbage iframe messages --- .../components/design/AppPreview/iframeTemplate.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/builder/src/components/design/AppPreview/iframeTemplate.js b/packages/builder/src/components/design/AppPreview/iframeTemplate.js index 9ae26bdaaf..1e3ff7c856 100644 --- a/packages/builder/src/components/design/AppPreview/iframeTemplate.js +++ b/packages/builder/src/components/design/AppPreview/iframeTemplate.js @@ -47,6 +47,18 @@ export default ` return } + // Parse received message + // If parsing fails, just ignore and wait for the next message + let parsed + try { + parsed = JSON.parse(event.data) + } catch (error) { + // Ignore + } + if (!parsed) { + return + } + // Extract data from message const { selectedComponentId, @@ -55,7 +67,7 @@ export default ` previewType, appId, theme - } = JSON.parse(event.data) + } = parsed // Set some flags so the app knows we're in the builder window["##BUDIBASE_IN_BUILDER##"] = true