Skip to content

fix(browser): only fire browserFinished when the Custom Tab actually terminates#2561

Open
OS-ruimoreiramendes wants to merge 3 commits into
mainfrom
fix/browser-android-launcher
Open

fix(browser): only fire browserFinished when the Custom Tab actually terminates#2561
OS-ruimoreiramendes wants to merge 3 commits into
mainfrom
fix/browser-android-launcher

Conversation

@OS-ruimoreiramendes

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

Copy link
Copy Markdown
Contributor

Description

Refactor the Android browser plugin to use ActivityResultLauncher for detecting when the Custom Tab has actually terminated, instead of inferring closure from lifecycle events via the previous EventGroup counter.
The EventGroup helper is removed. Browser now exposes setCustomTabLauncher and BrowserControllerActivity registers a launcher via registerForActivityResult, the browserFinished event is only fired when the launched Custom Tab activity ends.

Fixes #2554.

Change Type

  • Fix
  • Feature
  • Refactor
  • Breaking Change
  • Documentation
  • Other (CI, chores, etc.)

Rationale / Problems Fixed

When the user minimizes the Chrome Custom Tab to Picture-in-Picture (or backgrounds the app), the previous heuristic counted TAB_HIDDEN + unbindService and inferred the tab had closed firing browserFinished even though the tab was still open. After that, subsequent minimize/maximize/close events wouldn't fire the event again.

ActivityResultLauncher provides a single, deterministic callback only when the Custom Tab activity
truly finishes, so browserFinished now reflects the actual closed state.

Tests or Reproductions

Reproduced with the repo:
https://github.com/Prinzhorn/capacitor-android-browser-close-event

Manually tested on a physical Android device:

  • 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

Platforms Affected

  • Android
  • iOS
  • Web

@OS-ruimoreiramendes OS-ruimoreiramendes changed the title fix(browser): only fire browserFinished when the Custom Tab actually … fix(browser): only fire browserFinished when the Custom Tab actually terminates Jul 3, 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.

[Bug]: browserFinished on Android triggers when browser is minimized

1 participant