ionic-team / capacitor-plugins

Official plugins for Capacitor ⚡️
486 stars 563 forks source link

@capacitor/browser add a new BROWSER_CLOSED event #2072

Open kurtiev opened 3 months ago

kurtiev commented 3 months ago

Feature Request

Plugin

@capacitor/browser

Description

This is probably feature-request and bug issue as well :) I faced with problem when browser window is minimized (not closed) and event browserFinished Is triggered. I need to know when is was closed, not minimized. Take a look the attached screenshot, it has "minimize" control.

Platform(s)

Android only.

Preferred Solution

Add one more event here BROWSER_CLOSED or don't trigger BROWSER_FINISHED while inappbrowser is minimized.

Alternatives

Additional Context

IMG_2111

ionitron-bot[bot] commented 2 months ago

This issue has been labeled as type: bug. This label is added to issues that that have been reproduced and are being tracked in our internal issue tracker.

cornflakes commented 4 weeks ago

The PR: https://github.com/ionic-team/capacitor-plugins/pull/2125 would in turn fix this bug.

This bug is introduced in commit https://github.com/ionic-team/capacitor-plugins/commit/e2cdf3538b9741c5ec394abb14516ceaf5e12d43 by @ItsChaceD on January 22nd, 2024.

The issue arises because the URL is opened from an activity instead of the plugin itself. This causes the unbindService method (called from handleOnPause in the plugin) to be invoked before the open method (called from the activity callback). This results in group.enter() being called before group.reset(). Consequently, when group.leave() is triggered from the TAB_HIDDEN navigation event, the browserEventListener.onBrowserEvent(BROWSER_FINISHED) event fires incorrectly when the app goes into the background.

The pull request fixes the bug by changing the count threshold from count <= 0 to count < 0, preventing the unintended firing of the BROWSER_FINISHED event.

While the order of calls remains unchanged, modifying the count threshold achieves the same outcome of ensuring group.reset() happens before group.leave().