[Feature]: Official APIs to resolve/map ephemeral aria-refs to stable locators for LLM automation
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 35/100
- Issue 類型
- 功能
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- playwright, python
- 領域
- ai, devtools, testing-qa
研究方向
The issue requests new APIs to map ephemeral aria-refs to stable locators for LLM automation. Start by examining the existing aria_snapshot(mode="ai") implementation and the private codegen utilities. Look for internal methods like generateLocator or exposeConsoleApi. The goal is to design a public API that returns a Locator object or a structured selector bundle from a given aria-ref.
由索引模型根據 Issue 內容生成。
描述
🚀 Feature Request
With the rapid evolution of LLM-driven browser automation (especially leveraging Playwright's excellent aria_snapshot(mode="ai")), there is a growing need to bridge the gap between ephemeral AI session references (aria-ref=e5) and persistent, deterministic locators.
Currently, LLM agents perceive the page through temporary aria-ref identifiers. However, to "compile" these exploratory runs into reusable production scripts, developers must map these temporary refs to stable, best-practice locators (e.g., get_by_role, get_by_text).
While Playwright's internal codegen engine is powerful for this, it is currently locked behind private APIs. More importantly, simply generating a code string is often not enough; developers need a native, structured way to resolve an aria-ref into a stable Locator object or a "locator bundle" (role, name, css, xpath) to maintain this mapping throughout the automation pipeline.
Example
I would love to see official APIs that allow developers to programmatically resolve and map aria-refs to stable locators. This could take several forms, depending on what fits Playwright's design philosophy best:
- Structured Locator Resolution: Provide a method to resolve an aria-ref directly into a stable Locator object or a structured dictionary of candidate selectors.
- Expose Codegen/Console APIs: Alternatively, officially expose exposeConsoleApi or a dedicated codegen utility so developers can safely access window.playwright.generateLocator without relying on private internals.
Motivation
Right now, the only way to achieve this workflow is by reaching into Playwright's private internals:
# Python example of the current hacky workaround
await context._impl_obj._channel.send("exposeConsoleApi", None, {})
This is undocumented, fragile, and could break in any future release. Furthermore, it forces developers to manually parse and manage the relationship between the temporary ref and the resulting stable locator, without any native support for maintaining this mapping across complex agent workflows.
If this API were officially exposed, it would create a seamless, closed-loop workflow for AI agents:
- AI Perception: Get the page state using snapshot = await page.aria_snapshot(mode="ai")
- LLM Decision: The LLM decides to interact with an element, returning a reference like ref=e5
- Resolution & Mapping...
- Action & Persistence....
Playwright has already taken a huge step forward by introducing aria_snapshot(mode="ai"). Providing a native way to resolve these ephemeral AI refs into stable locators would be the perfect companion feature. It would bridge the gap between ephemeral AI sessions and persistent, deterministic automation, making Playwright the undisputed best framework for building reliable AI web agents.
Thank you for considering this request!
- 主要語言
- Python
- 星號
- 15k
- 分支
- 1.2k
- 平均合併
- 3 天 2 小時
- 30 天內合併 PR
- 9
環境準備
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
microsoft/playwright-python 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 75/100
microsoft/playwright-python#3208 · 2 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 68/100
microsoft/playwright-python#3186 ·
維護者通常 1 天內回覆
-
難度 4/5 3-5 天 新手友好度 45/100
microsoft/playwright-python#3216 ·
維護者通常 1 天內回覆
-
難度 5/5 一週以上 新手友好度 1/100
microsoft/playwright-python#3195 ·
維護者通常 1 天內回覆
-
難度 3/5 1-2 天 新手友好度 72/100
microsoft/playwright-python#3188 ·
維護者通常 1 天內回覆
查看 microsoft/playwright-python 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 86/100
維護者通常 1 天內回覆
-
難度 2/5 1-2 天 新手友好度 70/100
-
難度 2/5 1-3 小時 新手友好度 88/100
維護者通常 7 天內回覆
-
難度 2/5 1-3 小時 新手友好度 70/100
lmstudio-ai/mlx-engine#376 ·
-
難度 2/5 1-3 小時 新手友好度 72/100
pyiron/bagofholding#166 ·