Skip to content

Send the page time on pagehide instead of unload - #43

Open
boo-code wants to merge 1 commit into
PrestaShop:devfrom
boo-code:fix/statsdata-pagehide-instead-of-unload-40
Open

boo-code wants to merge 1 commit into
PrestaShop:devfrom
boo-code:fix/statsdata-pagehide-instead-of-unload-40

Conversation

@boo-code

@boo-code boo-code commented Nov 2, 2026

Copy link
Copy Markdown
Questions Answers
Description? With "Save page views for each customer" enabled, the module sends the time spent on a page from a $(window).on("unload") handler. Chrome deprecates unload listeners: Chrome 156 reports Unload event listeners are deprecated and will be removed on every front office page while the option is on, and where the unload permissions policy is off it reports the violation quoted in the issue.

The handler now listens to pagehide, which fires whenever the page is left, including into the back/forward cache. If the page is restored and left again, the time is sent a second time: Connection::setPageTime() sets time_end = time_start + time, so that only records the longer total.
Type? bug fix
BC breaks? no
Deprecations? no
Fixed ticket? Fixes #40
How to test? Enable the module's "Save page views for each customer" option, open a front office page in Chrome, then go to another page. Before: the Issues panel shows the unload deprecation, which disappears when the option is off. After: no deprecation, and the ps_connections_page row of the page that was left gets its time_end (8 seconds after time_start in my run).

Chrome deprecates unload listeners and blocks them where the unload permissions policy is off, so the time spent on a page was not sent there. pagehide fires when the page is left, including into the back/forward cache; Connection::setPageTime() overwrites time_end, so a later send only records the longer time.
@ps-jarvis

Copy link
Copy Markdown

Hello @boo-code!

This is your first pull request on statsdata repository of the PrestaShop project.

Thank you, and welcome to this Open Source community!

@github-project-automation github-project-automation Bot moved this to Ready for review in PR Dashboard Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready for review

Development

Successfully merging this pull request may close these issues.

Permissions policy violation: unload is not allowed

2 participants