← Back to microsoft/playwright
microsoft / playwright · Issue No. 42089
When using the Playwright Chrome Extension with an existing, user-profile Chrome session, some sign-in flows can invalidate the Playwright/CDP page target after the user clicks Sign in. The browser tab itself remains open and the login UI (including a QR code) is visibly rendered in that same tab, but subsequent calls such as page.screenshot() fail because the previously attached automation target is gone.
This is not a request for a site-specific adapter. I reproduced the pattern with a QR-code login modal in a Chinese web app, but the underlying case appears applicable to SPAs and sign-in flows that recreate their renderer/document or otherwise replace the attached target.
page / automation target is no longer usable, so page.screenshot() cannot complete.The user's Chrome profile, cookies, and login state remain in the existing browser. The failure is the lifetime of the attached automation target, not the browser state itself.
Please consider an explicit, extension-backed visible-tab capture fallback for the existing-browser extension mode.
A possible shape (names are only illustrative):
page object.browser_capture_visible_tab, backed by the extension Service Worker and chrome.tabs.captureVisibleTab.target_lost, timeout, or unsupported.This would be a fallback for an explicitly approved tab, not a replacement for normal Playwright screenshots. It could help agents keep an interactive login workflow alive long enough to show a human the visible QR code, then re-locate the page after login completes.
captureVisibleTab; the API should document this behavior.I have a local proof of concept that separates this fallback from the unstable Playwright page: the extension background stores the source tabId, observes the login modal, calls chrome.tabs.captureVisibleTab, and returns an in-memory PNG through a local MCP relay. It has been tested with a real current-Chrome QR-login modal after the original Playwright target became unusable.
I would be happy to prepare a focused PR with tests and documentation if the maintainers agree that this belongs in the extension/MCP design and can advise on the desired API and security model.
在使用 Playwright Chrome Extension 连接用户当前 Chrome 配置文件时,部分网页登录流程会在点击“登录”后使原先附着的 Playwright/CDP 页面目标失效。Chrome 标签页本身仍然存在,同一标签页内仍正常渲染登录弹层和二维码,但后续 page.screenshot() 会因原自动化目标已丢失而失败。
这不是某个网站的专用适配需求。虽然我是在一个中文网站的二维码登录弹层中复现的,但根因更通用:SPA 或登录流程可能重建文档/渲染上下文,或替换已经附着的自动化目标。
page/自动化目标已不可用,page.screenshot() 无法完成。用户的 Chrome 配置、Cookie 和登录状态都还留在原浏览器中;失效的是已附着自动化目标的生命周期,而不是浏览器状态本身。
建议在 existing-browser extension 模式中增加一个显式调用、由扩展后台执行的可见标签页截图兜底能力:
page 对象之外,保留用户已授权连接标签页的身份信息;browser_capture_visible_tab 的 MCP 操作(名称仅为示例),由扩展 Service Worker 调用 chrome.tabs.captureVisibleTab;target_lost、timeout、unsupported;该能力应只是用户明确授权标签页的兜底方案,而不是替代正常的 Playwright 截图。它可以让代理在交互式登录期间把当前可见二维码交给用户,然后在扫码完成后重新定位页面继续操作。
captureVisibleTab 可能需要目标窗口/标签页处于前台,API 需要明确这一行为。我已有本地最小原型:扩展后台保存源 tabId、观察登录弹层、调用 chrome.tabs.captureVisibleTab,并经本地 MCP Relay 返回仅在内存中传递的 PNG。已在真实当前 Chrome 的二维码登录弹层中验证:原 Playwright 目标不可用后,截图仍能成功。
如果维护者认可该能力属于扩展/MCP 的设计范围,并能指导期望的 API 形态与安全边界,我愿意按要求准备聚焦的 PR、测试与文档。
Relay reads this issue against the repository's contribution signals: the files it is likely to touch, how the maintainers triage work this size, and what the first contribution would exercise.
The full analysis for this issue is still being assembled. Until then, the description above and the thread on GitHub are the most reliable context.