Repository navigation
feat(dc): tell a lost opener from a real tab close on tab_closed - #289
Open
jakub-binczyk-cko wants to merge 3 commits into
Open
jakub-binczyk-cko wants to merge 3 commits into
jakub-binczyk-cko wants to merge 3 commits into
Conversation
The API can send opener_loss_handling (off / shadow / on) per APM payment method. When PO.js reports customer.canceled with reason tab_closed, DC reads the page focus and visibility synchronously, before PO.js refocuses the window: - off (or missing): today's cancel, nothing else; - shadow: report the verdict to telemetry, then cancel as today; - on: report it, and show the pending view instead of cancelling when the DC page is hidden or unfocused (the opener was severed, e.g. by COOP).
3 tasks done
Add po_flow=dynamic-checkout to the APM and saved APM redirect URLs. Checkout /redirect turns it into a first-party cookie, so /continue can show a "you can close this tab" landing when the PSP tab lost its link to the checkout, instead of opening the merchant site in a second tab.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The save-for-future flow still omits the redirect marker, so opener loss can send shoppers back to the merchant instead of the close-this-tab landing.
1 open issue
What changed in this PR
Adds rollout-controlled detection of lost payment-tab opener links in Dynamic Checkout, aiming to avoid false cancellations when a payment provider isolates its tab.
Changes:
- Adds
off,shadow, andonmodes with focus-based classification and telemetry. - Integrates opener-loss handling into APM flows and marks regular and saved-APM redirect URLs.
- Adds utility tests and bumps the version to
1.9.22.
| File | Description |
|---|---|
test/support/loadNamespace.ts |
Adds an isolated loader for opener-loss tests. |
test/dynamic-checkout/opener-loss.test.ts |
Tests modes, verdicts, telemetry, and redirect marking. |
src/dynamic-checkout/utils/opener-loss.ts |
Implements classification, telemetry, and redirect marking. |
src/dynamic-checkout/types/api.ts |
Adds the API rollout field. |
src/dynamic-checkout/references.ts |
Includes the new utility. |
src/dynamic-checkout/payment-methods/saved-apm.ts |
Integrates opener-loss handling and redirect marking. |
src/dynamic-checkout/payment-methods/apm.ts |
Handles opener loss in regular and save-for-future flows. |
package.json |
Bumps the version to 1.9.22. |
Review effort: Balanced
jakub-binczyk-cko
requested review from
a team and
szymon-mysiak-cko
and removed request for
a team
November 24, 2026 14:36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
When a PSP page sends
Cross-Origin-Opener-Policy(e.g. the MercadoLibre login page during a Mercado Pago payment), the browser cuts the link between the payment tab and Dynamic Checkout. PO.js then sees the tab as closed and DC shows "payment cancelled", even though the shopper is still paying.This PR lets DC tell that case from a real tab close, behind a rollout mode sent by the API, so we can first measure the check in production (
shadow) before it changes anything for shoppers.Design: RFC: Mercado Pago COOP-isolated return flow, section 4.1–4.2.
Solution
DynamicCheckoutOpenerLossUtils(src/dynamic-checkout/utils/opener-loss.ts).customer.canceledwithreason: "tab_closed". The overlay's Cancel and other errors are unchanged.opener_loss_handlingfield on the APM payment method (off/shadow/on). A missing or unknown value isoff.shadowandonreport the verdict to telemetry (info): mode, verdict,gateway_name,has_focus,visibility_state, ms since the action started, user agent.apm.ts(regular and save-for-future flow) andsaved-apm.tscall it as the first thing in thehandleActionerror callback. PO.js callswindow.focus()right after that callback (ActionHandler.cancelf()→refocus()), so the page state must be read before.off: no change.shadow: telemetry, thenpayment_cancelledas today.onand a severed opener: the pending view, no event.po_flow=dynamic-checkout. Checkout/redirectstores it in a first-party cookie, so/continuecan show a "you can close this tab" landing instead of forwarding to the merchant when the opener is gone (checkout PR linked below). Independent of the rollout mode; raw processout.js integrations don't send it.Demo
Tested on staging together with #290 and processout/api#6348 (
opener_loss_handling: onfor a test project), Mercado Pago MX sandbox. The APM redirect URL carriedpo_flow=dynamic-checkout; after a simulated lost opener, telemetry reportedmode: on,verdict: severed_link(has_focus: false,visibility_state: hidden) and DC didn't show "payment cancelled".Checklist
yarn bump-versionNotes
ononly together with feat(POINT-3697)(dc): poll the transaction after a lost opener #290, which adds status polling and a Cancel button to the pending view. Without it,onshows a plain pending view;offandshadoware safe on their own.refocus()simulated: a severed opener was always hidden or unfocused, and after a real close the DC page was focused 0.07–0.45 s before PO.js saw the closed tab. Mobile browsers and webviews are whatshadowmode is for.opener_loss_handlingfield) is processout/api#6348; the field name matches.ActionHandleris unchanged.Jira Issue
Part of the Mercado Pago COOP work (DC side of the lost-opener check); the Jira task stays open for the follow-ups above.
Testing
test/dynamic-checkout/opener-loss.test.ts(23 tests, incl. the redirect marker): mode parsing, verdicts, every mode × page state, non-tab_closedcancels ignored, page state read once, telemetry payload.yarn test(293 tests),yarn buildandeslintpass.verdict: severed_link(has_focus: false,hidden); closing the tab with the DC page focused gaveverdict: real_close(has_focus: true,visible). The redirect URL carriedpo_flow=dynamic-checkout.