fix(sdk): prevent lack of parent domain from throwing error

This commit is contained in:
Jeremy Kahn 2023-11-23 15:14:55 -06:00
parent 7bceba5acb
commit 35e0b88cbe

View File

@ -45,8 +45,12 @@ export const isConfigMessageEvent = (
event: MessageEvent event: MessageEvent
): event is ConfigMessageEvent => { ): event is ConfigMessageEvent => {
const queryParams = new URLSearchParams(window.location.search) const queryParams = new URLSearchParams(window.location.search)
const parentDomain = queryParams.get(QueryParamKeys.PARENT_DOMAIN)
if (parentDomain === null) return false
const { origin: parentFrameOrigin } = new URL( const { origin: parentFrameOrigin } = new URL(
decodeURIComponent(queryParams.get(QueryParamKeys.PARENT_DOMAIN) ?? '') decodeURIComponent(parentDomain)
) )
if (event.origin !== parentFrameOrigin) return false if (event.origin !== parentFrameOrigin) return false