Forum Discussion
Playwright MCP browser context is lost after 8-12 minutes of idle time.
hi shobhit-vishwakarma​ Given the architecture, I wouldn't immediately assume that Playwright itself is closing the browser context. The 8-12 minute window makes me suspect a timeout somewhere in the connection chain, especially with Azure Container Apps and the long-lived connection between your MCP server and the Chrome extension.
I'd investigate the issue layer by layer:
- Check Azure Container Apps logs around the exact time the context is lost.
- Verify whether the MCP server process/container is being restarted or scaled down.
- Check whether the webhook/HTTP connection between the extension and MCP relay has an idle timeout.
- Confirm whether the CDP connection is still alive after the idle period.
- Check Playwright MCP logs to determine whether the browser context actually disappeared or whether the MCP server simply lost its reference to it.
I would also avoid automatically calling browser_close and creating a new session as the first recovery action. If the browser is still running locally, try implementing a reconnect/recovery mechanism first. The MCP server could periodically check the connection or re-establish communication with the existing browser before deciding that the context is genuinely gone.
A heartbeat or lightweight keep-alive may help if the issue is caused by an idle network connection, but I'd first identify exactly which component is timing out. Otherwise, you could end up masking the underlying problem.
One other thing I'd consider is session state management. For a production system, I'd treat the browser context as a separate long-lived resource and maintain a session ID/state mapping on the server side. If the MCP connection drops, the agent should attempt to reconnect to the existing session rather than assuming the browser context has been destroyed.
The fact that this happens consistently after roughly 8-12 minutes is a useful clue. I'd focus on finding which component has a timeout in that range. Once you know whether it's Azure Container Apps, the webhook connection, the CDP channel, or Playwright MCP itself, the solution should become much clearer.