From 5cd2ea73d451c362666503642a00010ccea782b0 Mon Sep 17 00:00:00 2001 From: Carl Gieringer <78054+carlgieringer@users.noreply.github.com> Date: Mon, 1 May 2023 19:57:44 -0700 Subject: [PATCH] Handle MessageEvent.data of 'undefined' (#408) Signed-off-by: Carl Gieringer <78054+carlgieringer@users.noreply.github.com> --- premiser-ui/src/WindowMessageHandler.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/premiser-ui/src/WindowMessageHandler.tsx b/premiser-ui/src/WindowMessageHandler.tsx index ef67a9d1..d31facc9 100644 --- a/premiser-ui/src/WindowMessageHandler.tsx +++ b/premiser-ui/src/WindowMessageHandler.tsx @@ -13,7 +13,7 @@ import { } from "./identifiers"; import { flows, goto } from "./actions"; import { toJson } from "howdju-common"; -import { every } from "lodash"; +import { every, isObject } from "lodash"; /** Dispatch-bound action creators needed by WindowMessageHandler. */ export interface WindowMessageHandlerActionCreators { @@ -34,7 +34,13 @@ export default class WindowMessageHandler { this.actionCreators = actionCreators; } - handleEvent(event: MessageEvent) { + handleEvent(event: MessageEvent) { + if (!isObject(event.data)) { + // For reasons I don't understand, on mobile Safari, only in prod (`https`-only?) the + // event.data is sometimes the string "undefined". + logger.warn(`MessageEvent.data was not an object: ${toJson(event.data)}`); + return; + } if (event.source === window) { if ("howdjuTrackingConsent" in event.data) { const { enabled } = event.data.howdjuTrackingConsent;