Forum Discussion
Playwright MCP browser context is lost after 8-12 minutes of idle time.
An 8-12 minute pattern sounds more like a connection, relay, or Azure Container Apps lifecycle timeout than a normal Playwright browser-context timeout. A Playwright context does not normally disappear simply because no browser actions were sent for a few minutes. However, once the CDP connection or the MCP server process is lost, the server-side Playwright objects are no longer valid, even if the user's Chrome window and tab are still open.
Start with Azure Container Apps. Set the MCP relay to keep at least one replica running, so it does not scale to zero while the agent is idle. Then check the container logs at the time of failure. Log three simple events: when the extension connects, when it disconnects, and when the MCP server process starts or stops. This will show whether the problem is the browser connection, the relay, or a container restart.
Next, make sure the extension uses a real persistent connection, such as WebSocket, rather than depending only on normal HTTP webhook calls. Send a small ping message every 30-60 seconds and have the extension reply with pong. If several pings are missed, reconnect the extension automatically. The ping should only prove that the connection is alive; it should not open pages, click anything, or otherwise affect the user's browser.
The recovery logic should reconnect before it closes anything. Keep a record of the logical session ID and the Chrome tab ID when the session begins. After a disconnect, ask the extension whether that tab still exists. If it does, reconnect to the same running browser and attach to that tab again. Only call browser_close when the extension confirms that the browser or tab has actually gone away. This preserves the open page and, in most cases, the existing login session.
Finally, test the setup deliberately: leave the agent idle for 15, 30, and 60 minutes, then send one harmless request each time. Compare the relay logs, Azure Container Apps events, and extension logs. That should identify the layer that is ending the session before adding more retry logic.