ampproject / ampproject/worker-dom
[Feature Request] Support for page unload detection in sandboxed mode
- Dominant language
- TypeScript
- Stars
- 3.3k
- Forks
- 154
- PR merge metrics
- No merged PRs in 30d
Description
Hey AMP/worker-dom team,
At Permutive, we've been using the `sandboxed` mode of amp-script for our script. The change to support this in worker-dom was introduced in #1042
One request we had and that I was discussing with @samouri is the ability to detect a page unload event.
Right now, in sandboxed mode we cannot attach any event listeners, and this is understandable based on the restrictions that the `sandboxed` mode places on scripts running within it.
However, I was wondering if we can allow an event listener to be attached for a page unload event. Based on our cross device testing we currently use the `pagehide` event on desktop and `visibilitychange` for mobile.
I was wondering if we can get access to both while our script is running in sandboxed mode?
### Use Case
In response to a page unload event, we wish to be able to send a beacon request with some engagement related metrics from the page.
Thanks!
Contributor guide
Research direction
Start by reviewing the sandboxed-mode change introduced in #1042 and the current restrictions on event listeners. Trace how pagehide and visibilitychange are handled, then define completion as allowing both events in sandboxed mode for the stated page-unload beacon use case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend, web-dev
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100