export type MobileWebViewHistoryStateMessage = { canGoBack: boolean; }; export function parseMobileWebViewHistoryStateMessage( rawMessage: string, ): MobileWebViewHistoryStateMessage | null { try { const value = JSON.parse(rawMessage) as unknown; if (!value || typeof value !== 'object') { return null; } const candidate = value as { type?: unknown; canGoBack?: unknown; }; if ( candidate.type !== 'genarrative.mobile.historyState' || typeof candidate.canGoBack !== 'boolean' ) { return null; } return { canGoBack: candidate.canGoBack, }; } catch { return null; } }