ampproject / ampproject/worker-dom

Is window.onbeforeunload impelementation acceptable?

Open
#1,056 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
3.3k
Forks
154
PR merge metrics
No merged PRs in 30d

Description

I made a branch ( [https://github.com/andrei0x309/worker-dom/tree/window-on-before-unload](https://github.com/andrei0x309/worker-dom/tree/window-on-before-unload) ) with `window.onbeforeunload` implementation and demo, I think it's useful, from what I see onbeforeunload has 3 useful applications:

1. show a loader when navigating to simulate a SPA( works well on modern browsers because they only render elements when they are loaded which means no white pages like in the old days)
2. alerting the user of unsaved data
3. analytics

The only problem I see is that some developers might abuse this feature( since it transfers a function on the main thread), so that's why I am asking if such a feature is acceptable to know if I should write some tests and submit a PR.

Thanks.

Contributor guide

Open the contributing guide

Research direction

Review the window-on-before-unload branch and its demo first; the issue names no test file or entry point. Determine whether the proposed worker-to-main-thread behavior is acceptable, then define tests for the supported use cases before submitting a pull request.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.