Chrome is changing its behavior to allow pages with active WebSocket connections to enter the Back/Forward Cache. To achieve this, active WebSockets will now be disconnected when a page is cached. Previously, active WebSocket connections prevented pages from entering BFCache. The BackForwardCacheForWebSocketsAllowed policy is provided as a temporary escape hatch for enterprises. Setting this policy to Disabled will revert to the previous behavior (preventing pages with active WebSockets from entering BFCache), which will prevent breakage in legacy apps that lack WebSocket reconnection logic.
Currently, any active WebSocket connection forces the browser to discard the page when the user navigates away, preventing it from being stored in the Back/Forward Cache (BFCache). We are changing this behavior to allow these pages to be cached by closing any active WebSocket connections upon entry. This approach mirrors the behavior for WebTransport. For web developers, this change is designed to be compatible with existing patterns. When a page is restored from BFCache, the browser fires the error and close events, enabling applications to simply trigger their existing reconnection logic to pick up where they left off.