next.js: Error was not caught DOMException: Failed to read the 'localStorage' property from 'Window': Access is denied for this document

Bug report

Following the tutorial first steps, expecting to see a 404 page when running npm run dev but seeing an empty screen with the following error in console:

localhost/:1 GET http://localhost:3000/ 404 (Not Found)
Navigated to http://localhost:3000/
react-dom.development.js:27773 Download the React DevTools for a better development experience: https://fb.me/react-devtools
index.js:1 Error was not caught DOMException: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.
    at initializeBuildWatcher (http://localhost:3000/_next/static/runtime/main.js?ts=1580234262737:6291:39)
    at http://localhost:3000/_next/static/runtime/main.js?ts=1580234262737:7260:40
console.<computed> @ index.js:1
(anonymous) @ next-dev.js:6
Promise.catch (async)
(anonymous) @ next-dev.js:6
./node_modules/next/dist/client/next-dev.js @ next-dev.js:6
__webpack_require__ @ bootstrap:792
checkDeferredModules @ bootstrap:45
webpackJsonpCallback @ bootstrap:32
(anonymous) @ main.js?ts=1580234262737:1
on-demand-entries-utils.js:5 GET http://localhost:3000/ 404 (Not Found)
(anonymous) @ on-demand-entries-utils.js:5
handleMessage @ eventsource.js:1
on-demand-entries-utils.js:5 GET http://localhost:3000/ 404 (Not Found)
(anonymous) @ on-demand-entries-utils.js:5
handleMessage @ eventsource.js:1

To Reproduce

Chrome 80 which will be released in Feb has some important changes for 3rd party cookie policy: https://blog.chromium.org/2019/10/developers-get-ready-for-new.html https://web.dev/samesite-cookies-explained/

To reproduce this error on chrome 79, turn these two flags on:

chrome://flags/#cookies-without-same-site-must-be-secure chrome://flags/#same-site-by-default-cookies

Then follow the tutorial and see the blank page when starting the dev server

Expected behavior

To see a 404 page

Screenshots

image

System information

Next: 9.2.1 Node: v12.13.1 OS: Ubuntu 19.10 Chrome: Version 79.0.3945.130 (Official Build) (64-bit)

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 18 (11 by maintainers)

Most upvoted comments

There is a similar error with disabled localStorage in general.

When doing so for chrome see stack-overflow on how to do it. And using the described scenario of @rafaelalmeidatk the app will fail when accessing the page.

The problem for this specific case for me seems to be that the prerender-indicator is accessing the localStorage without testing if it is enabled : https://github.com/zeit/next.js/blob/81fd704681fcac4d241e6f94bb45232ddc403e72/packages/next/client/dev/prerender-indicator.js#L43 https://github.com/zeit/next.js/blob/81fd704681fcac4d241e6f94bb45232ddc403e72/packages/next/client/dev/prerender-indicator.js#L74

Not sure if this relates to the other issues.

@lfades the issue is present for all Storyblok backends. I run on newest stable version of NextJS and the issue just got introduced with FastRefresh

This issue still happens in the latest nextjs when behind an iframe.

Error was not caught DOMException: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.
    at initializeBuildWatcher (webpack-internal:///./node_modules/next/dist/client/dev/prerender-indicator.js:47:38)
    at eval (webpack-internal:///./node_modules/next/dist/client/next-dev.js:96:40)
eval @ next-dev.js?53bc:97
Promise.catch (async)
eval @ next-dev.js?53bc:32
eval @ next-dev.js?53bc:32
./node_modules/next/dist/client/next-dev.js @ main.js?ts=1602796145388:1377
__webpack_require__ @ webpack.js?ts=1602796145388:873
checkDeferredModules @ webpack.js?ts=1602796145388:46
webpackJsonpCallback @ webpack.js?ts=1602796145388:33
(anonymous) @ webpack.js?ts=1602796145388:1015
(anonymous) @ webpack.js?ts=1602796145388:1023

@dohomi In that case please create a new issue with a reproduction that we can take a look at 🙏