Skip to content

Commit

Permalink
fix: Proxy tlink API requests to window.opener instead of window.pare…
Browse files Browse the repository at this point in the history
…nt when opened in popup window
  • Loading branch information
micwallace committed Nov 21, 2024
1 parent 1d22b12 commit 649f594
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions javascript/tokenscript-viewer/src/components/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ export class AppRoot {
response: await getTurnstileToken(turnstileRequest.siteKey)
};
}

if (this.viewerType.indexOf("tlink"))
throw new Error("This TLink API is not available in this context.");
}

return new Promise((resolve, reject) => {
Expand All @@ -181,9 +184,9 @@ export class AppRoot {
}
}

window.addEventListener('message', messageHandler)
window.addEventListener('message', messageHandler);

window.parent.postMessage({ type: 'TLINK_API_REQUEST', data }, '*')
(window.opener ?? window.parent).postMessage({ type: 'TLINK_API_REQUEST', data }, '*')

setTimeout(() => {
window.removeEventListener('message', messageHandler)
Expand Down

0 comments on commit 649f594

Please sign in to comment.