Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page leave confirmation modal conflicts with Matomo(beforeunload event) #20165

Open
pavelspichonak opened this issue Jan 6, 2023 · 2 comments
Labels
Bug For errors / faults / flaws. c: Tracking Issues related to getting data into Matomo

Comments

@pavelspichonak
Copy link

Expected Behavior

Browser window is not closed and user sees browser confirmation modal.

Current Behavior

In some browsers browser window is closed and user does see browser confirmation modal.
In some browsers browser window is closed and user sees browser confirmation modal.

Context

In our application when some form has changes and user tries to close browser window, we show confirmation modal using beforeunload event like this:

const handleWindowClose = useCallback((event) => {
  (event || window.event).returnValue = true;
}, []);

useEffect(() => {
  if (formHasChanges) {
    window.addEventListener('beforeunload', handleWindowClose);
  } else {
    window.removeEventListener('beforeunload', handleWindowClose);
  }
}, [formHasChanges]);

All worked as expected, user saw browser confirmation modal and browser window was open until user clicks confirmation button in this modal.

But then we added Matomo to our application and after that in some browsers user saw browser confirmation modal in some user did not see it and browser window was closed. It was closed even before user clicked confirmation button in the modal.

After investigation it looks like this bug is related to beforeUnloadHandler function in Matomo script. Looks like this do/while execution takes too much time and as far as I remember browser closes window if beforeunload event execution takes too much time.

Your Environment

  • Matomo Version: 4.12.3
  • PHP Version: 8.1.12
  • Browser: Opera 94.0.4606.38 (x86_64), Safari 6.2 (18614.3.7.1.5)
  • Operating System: MacOS, Windows 10
@pavelspichonak pavelspichonak added Potential Bug Something that might be a bug, but can't be reproduced (yet). To Triage An issue awaiting triage by a Matomo core team member labels Jan 6, 2023
@bx80
Copy link
Contributor

bx80 commented Jan 8, 2023

Thanks for reporting this @pavelspichonak, we'll need to review this delay loop and how it interacts with modals displayed via beforeUnloadHandler when plugin unload events exceed the timeout.

I'll assign this issue for prioritisation 👍

@bx80 bx80 added this to the For Prioritization milestone Jan 8, 2023
@bx80 bx80 added Bug For errors / faults / flaws. c: Tracking Issues related to getting data into Matomo and removed Potential Bug Something that might be a bug, but can't be reproduced (yet). To Triage An issue awaiting triage by a Matomo core team member labels Jan 8, 2023
@pavelspichonak
Copy link
Author

Hi @bx80. Is there any progress on this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For errors / faults / flaws. c: Tracking Issues related to getting data into Matomo
Projects
None yet
Development

No branches or pull requests

2 participants