Skip to content

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
masterfrom
feat/dc-opener-loss-verdict
Open

jakub-binczyk-cko wants to merge 3 commits into
masterfrom
feat/dc-opener-loss-verdict

Conversation

@jakub-binczyk-cko

@jakub-binczyk-cko jakub-binczyk-cko commented Nov 17, 2026 •

Copy link
Copy Markdown

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

  • New DynamicCheckoutOpenerLossUtils (src/dynamic-checkout/utils/opener-loss.ts).
    • Only acts on customer.canceled with reason: "tab_closed". The overlay's Cancel and other errors are unchanged.
    • Mode comes from the new opener_loss_handling field on the APM payment method (off / shadow / on). A missing or unknown value is off.
    • Verdict: if the DC page is focused and visible, it's a real close. Otherwise the opener was severed: after a real close the browser activates the DC page before PO.js notices the closed tab.
    • shadow and on report 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) and saved-apm.ts call it as the first thing in the handleAction error callback. PO.js calls window.focus() right after that callback (ActionHandler.cancelf() → refocus()), so the page state must be read before.
    • off: no change.
    • shadow: telemetry, then payment_cancelled as today.
    • on and a severed opener: the pending view, no event.
  • APM and saved APM redirect URLs get po_flow=dynamic-checkout. Checkout /redirect stores it in a first-party cookie, so /continue can 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: on for a test project), Mercado Pago MX sandbox. The APM redirect URL carried po_flow=dynamic-checkout; after a simulated lost opener, telemetry reported mode: on, verdict: severed_link (has_focus: false, visibility_state: hidden) and DC didn't show "payment cancelled".

Checklist

  • I bumped the version of the project using yarn bump-version
  • I have checked the code for any potential issues
  • I tested my changes in the browser

Notes

  • Use on only 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, on shows a plain pending view; off and shadow are safe on their own.
  • The decision rule was tested in a local proof of concept in Chrome, Firefox and Safari (desktop), with PO.js 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 what shadow mode is for.
  • The API side (LaunchDarkly flag and the opener_loss_handling field) is processout/api#6348; the field name matches.
  • ActionHandler is 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

  • New test/dynamic-checkout/opener-loss.test.ts (23 tests, incl. the redirect marker): mode parsing, verdicts, every mode × page state, non-tab_closed cancels ignored, page state read once, telemetry payload.
  • yarn test (293 tests), yarn build and eslint pass.
  • Staging with feat(POINT-3697)(dc): poll the transaction after a lost opener #290 and processout/api#6348, Mercado Pago MX sandbox: a simulated lost opener gave verdict: severed_link (has_focus: false, hidden); closing the tab with the DC page focused gave verdict: real_close (has_focus: true, visible). The redirect URL carried po_flow=dynamic-checkout.

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).
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.
@jakub-binczyk-cko jakub-binczyk-cko self-assigned this Nov 18, 2026
@jakub-binczyk-cko
jakub-binczyk-cko marked this pull request as ready for review November 24, 2026 14:17
Copilot AI balanced review requested due to automatic review settings November 24, 2026 14:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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, and on modes 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
jakub-binczyk-cko requested review from a team and szymon-mysiak-cko and removed request for a team November 24, 2026 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants