是 Ray 不是 Array

整理這些技術筆記真的很花時間,如果你願意 關閉 Adblock 支持我,我會把這份感謝轉換成更多「踩坑轉避坑」的內容給你!ヽ(・∀・)ノ

Advertisement
2022-01-10 雜談

本地開發遇到「Uncaught DOMException: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.」

前言

最近遇到一個很特別的狀況,也就是在本地開發時 localStorage 會噴「Uncaught DOMException: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.」這個錯,所以紀錄一下這個問題。

問題點

找了一份有使用 localStorage 開發的專案,然後使用 Live Server 等模擬伺服器開啟之後,開啟瀏覽器輸入 http://localhost:5500/,接下來就會在 Console 控制台看到以下錯誤訊息

Uncaught DOMException: Failed to read the ‘localStorage’ property from ‘Window’: Access is denied for this document.
Uncaught DOMException: Failed to read the ‘sessionStorage’ property from ‘Window’: Access is denied for this document.

Failed to read the xxxxx property from Window: Access is denied for this document

解決方式

解決方式非常簡單,只需要將該網域加入到允許網域內就可以正常運作了

允許 Cookie

但有趣的事情是,第三方 Cookie 封鎖的現象只會在 http://localhost:5500/ 這個網域,而不會在 http://127.0.0.1:5500/ 網域。

參考文獻

整理這些技術筆記真的很花時間,如果你願意 關閉 Adblock 支持我,我會把這份感謝轉換成更多「踩坑轉避坑」的內容給你!ヽ(・∀・)ノ

Advertisement

你的支持會直接轉換成更多技術筆記

如果我的筆記讓你少踩一個坑、節省 Debug 的時間,
也許你可以請我喝杯咖啡,讓我繼續當個不是 Array 的 Ray ☕

buymeacoffee | line | portaly

Terminal

分享這篇文章

留言

© 2025 Ray. All rights reserved.

Powered by Ray Theme