Skip to content

fix: only fire browserClosed when the custom tab actually terminates#58

Open
OS-ruimoreiramendes wants to merge 4 commits into
mainfrom
fix/browser-close-events
Open

fix: only fire browserClosed when the custom tab actually terminates#58
OS-ruimoreiramendes wants to merge 4 commits into
mainfrom
fix/browser-close-events

Conversation

@OS-ruimoreiramendes

@OS-ruimoreiramendes OS-ruimoreiramendes commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

⚠️ 🤖 AI-assisted PR with Claude

Description

Refactor the Custom Tabs flow so browserClosed fires only when the Custom Tab actually terminates. Uses ActivityResultLauncher in OSIABCustomTabsControllerActivity instead of inferring closure from TAB_HIDDEN in OSIABCustomTabsSessionHelper.

Files changed:

  • OSIABCustomTabsControllerActivity — registers ActivityResultLauncher, launches the CCT from an intent extra, finishes only on the launcher result. Start animations preserved via ActivityOptionsCompat.makeCustomAnimation reconstructed from extras (exit animations travel inside the intent).
  • OSIABCustomTabsRouterAdapter — builds the CCT intent up front and hands it to the controller activity; listens for EVENT_CUSTOM_TABS_DESTROYED to fire onBrowserFinished.
  • OSIABCustomTabsSessionHelper — removed the TAB_HIDDEN interpretation and the isCustomTabsActivityOnTop / pendingTabHiddenEvent state. Only handles NAVIGATION_FINISHED → BrowserPageLoaded.

Context

CustomTabsCallback.onNavigationEvent(TAB_HIDDEN) fires on close, PiP minimize, home button, task switch — the previous heuristic couldn't disambiguate them and fired browserClosed prematurely (notably on PiP).

Same approach as @capacitor/browser #2561, which fixed the equivalent issue in capacitor-plugins#2554.

Type of changes

  • Fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Refactor (cosmetic changes)
  • Breaking change (change that would cause existing functionality to not work as expected)

Tests

Unit tests updated to match the new event flow.

Manually tested on a physical Android device using the example app of capacitor-os-inappbrowser, which uses an AAR of this PR:

  • Open browser → close via back gesture / X button → browserFinished fires once
  • Open browser → minimize to PiP → maximize → close → browserFinished fires once, only on close
  • Open browser → send app to background → return to app → close browser → browserFinished fires once,
    only on close

Checklist

  • Code follows code style of this project
  • CHANGELOG.md file is correctly updated
  • Changes require an update to the documentation
    • Documentation has been updated accordingly

@OS-ruimoreiramendes OS-ruimoreiramendes changed the title Fix/browser close events fix: only fire browserFinished when the Custom Tab actually terminates Jul 9, 2026
@OS-ruimoreiramendes OS-ruimoreiramendes marked this pull request as ready for review July 9, 2026 11:19
@OS-ruimoreiramendes OS-ruimoreiramendes changed the title fix: only fire browserFinished when the Custom Tab actually terminates fix: only fire browserClosed when the custom tab actually terminates Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant