Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] send an event before redirecting anything in top context #842

Open
kashif-m opened this issue Dec 17, 2024 · 0 comments · May be fixed by #860
Open

[FEATURE] send an event before redirecting anything in top context #842

kashif-m opened this issue Dec 17, 2024 · 0 comments · May be fixed by #860
Assignees
Labels
Enhancement / Refactoring New feature or request or any refactoring hyperswitch-web This issue relates to hyperswitch-web SDK.

Comments

@kashif-m
Copy link
Contributor

kashif-m commented Dec 17, 2024

Problem statement
Payment link / SDK integrations where beforeunload event is registered displays a confirmation to the user before redirection.

Screenshot 2024-12-17 at 12 32 32 PM

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 -

            const fnUsedDuringAddEventListener = function (event) {
                event.preventDefault();
                event.returnValue = '';
            };

            window.addEventListener('beforeunload', fnUsedDuringAddEventListener);

The integrator will also need to include below code snippet in their integration for removing the beforeunload event which is handled by the SDK itself

        <script src="URL TO  HyperLoader.js"
            onload="initializeBeforeUnloadRemoval()">
            function initializeBeforeUnloadRemoval() {
                window.removeBeforeUnloadEventListener(fnUsedDuringAddEventListener)
            }
        </script>

Implementation
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 of beforeunload 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

@kashif-m kashif-m added Enhancement / Refactoring New feature or request or any refactoring hyperswitch-web This issue relates to hyperswitch-web SDK. labels Dec 17, 2024
@kashif-m kashif-m self-assigned this Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement / Refactoring New feature or request or any refactoring hyperswitch-web This issue relates to hyperswitch-web SDK.
Projects
None yet
1 participant