[Violation] Permissions policy violation: unload is not allowed in this document. #91378
Unanswered
how2j-coder
asked this question in
Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
[Violation] Permissions policy violation: unload is not allowed in this document.
Description
When running a Next.js application in Chrome/Edge browsers, the console shows a permissions policy violation warning:
[Violation] Permissions policy violation: unload is not allowed in this document.Steps to Reproduce
npx create-next-app@latestnpm run devhttp://localhost:3000in Chrome/EdgeExpected behavior: No permissions policy violations in console.
Actual behavior: Console shows:
[Violation] Permissions policy violation: unload is not allowed in this document.Code Example
The error appears without any custom
unloadevent listeners. However, it can be reproduced by adding:Root Cause
Chrome/Edge browsers have implemented stricter Permissions Policies to improve performance and security. The
unloadevent is being deprecated because it prevents pages from using the back/forward cache (bfcache), which significantly impacts user experience during navigation.The default Permissions Policy in modern browsers restricts
unloadunless explicitly allowed.Environment
Possible Solutions
1. Replace
unloadwithpagehide(Recommended)2. Configure Permissions Policy in Next.js
3. Use Middleware (Next.js 12+)
Related Issues
unload: https://developer.chrome.com/blog/page-lifecycle-api/#the-unload-eventAdditional Context
unloadlisteners are added, suggesting Next.js internals or third-party libraries might be using it.pagehideinstead ofunloadenables bfcache, improving navigation performance by up to 10x.visibilitychange+sendBeaconinstead ofunload.Workaround Status
unloadusage in codebasepagehide/pageshow)Request
unloadevents?pagehideoverunloadunloadLabels:
bug,browser-compatibility,performance,documentationAdditional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions