At the finishing stage of a browser game, I sometimes find myself pausing over the question of what to do when a user opens the same game in multiple tabs.
To deal with this, I had been using WebSocket so that if the same game was opened in multiple tabs, a warning would be shown and the game would be made unplayable.
However, the other day, while casually looking through the MDN documentation, I learned that there is a feature called Web Locks.
It is possible to detect multiple tabs playing the same game with WebSocket as well, but it requires writing code on both the frontend and the server side.
Also, in my implementation, the server would detect it via WebSocket and then return a warning, so there was a slight delay in detection, and it didn’t always fully function as a guard at the exact moment the page was opened.
In that sense, if the goal is simply to prevent multiple instances within the same browser, Web Locks is simpler in terms of code, and since it completes within the browser, the response is faster.
Recently, I had been relying almost entirely on asking Codex to “make this,” but unless I wander around the internet and explore technologies like before Coding AI existed, I wouldn’t have been able to find Web Locks.
Web development is not yet something that can be entirely left to AI.