[FEATURE] send an event before redirecting anything in top context #842
Labels
Enhancement / Refactoring
New feature or request or any refactoring
hyperswitch-web
This issue relates to hyperswitch-web SDK.
Problem statement
Payment link / SDK integrations where
beforeunload
event is registered displays a confirmation to the user before redirection.Aim is to bypass such popups in payment link / SDK integrations.
Proposed solution
Removing event listeners is straightforward and can be done using removeEventListener. But child contexts cannot access cross origin parent's context for removing such event listeners.
Aim here is for the SDK to handle the removal of such event listeners rather than relying on the merchant's to handle this themselves.
This solution offers a straightforward way for the integrators to initialize an event removal subscription offered by the SDK by passing the reference to the function which was used during addition of the
beforeunload
event.For example, let's say the integrator used below code for initializing the
beforeunload
event -The integrator will also need to include below code snippet in their integration for removing the
beforeunload
event which is handled by the SDK itselfImplementation
Redirections in SDK happen using a common place using the fn
replaceRootHref
. Before any redirections, trigger postMessage to the top context requesting the SDK in top context to handle the removal ofbeforeunload
events.References
beforeunload - https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event
postMessage - https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage
removeEventListener - https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener
The text was updated successfully, but these errors were encountered: