Description
Description
After the recent update to Chrome in 2024, which blocks third-party cookies by default, our game, which is hosted in an iframe on a games platform, encounters a critical issue. Chrome's new policy leads to a situation where accessing localStorage
throws an error if no user consent is given. Our game uses colyseus.js
, which seems to internally access localStorage
and thus causes a crash upon page load.
Error Encountered
The specific error message we encounter is:
Uncaught DOMException: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.
Possible Source of the Error
This issue seems to originate from the Storage.ts class, particularly in the getStorage
function, which attempts to access the localStorage
object to check its availability in the current environment.
Suggested Solution
A potential solution to circumvent this issue could be wrapping the window.localStorage
access in a try / catch
block. This would gracefully handle the exception caused by Chrome's third-party cookie policy and prevent the application from crashing.
Steps to Reproduce
- Host a game that uses
colyseus.js
in an iframe on a third-party platform. - Load the game in the latest version of Chrome with default settings (third-party cookies blocked).
- Observe the crash upon page load with the aforementioned error in the console.
or: Try out our particular game at Poki with third party cookie blocking enabled.
I believe this issue is critical for any web-based games or applications using colyseus.js
in similar environments and would greatly appreciate a timely resolution. Thank you for your attention to this matter!