Skip to content

Commit

Permalink
Handle MessageEvent.data of 'undefined' (#408)
Browse files Browse the repository at this point in the history
Signed-off-by: Carl Gieringer <78054+carlgieringer@users.noreply.github.com>
  • Loading branch information
carlgieringer authored May 2, 2023
1 parent b22b9fa commit 5cd2ea7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions premiser-ui/src/WindowMessageHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -34,7 +34,13 @@ export default class WindowMessageHandler {
this.actionCreators = actionCreators;
}

handleEvent(event: MessageEvent<WindowMessage>) {
handleEvent(event: MessageEvent<WindowMessage | "undefined">) {
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;
Expand Down

0 comments on commit 5cd2ea7

Please sign in to comment.