豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/tool-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,16 @@ so returned values have to JSON-serializable.

- **args** (array) _(optional)_: An optional list of arguments to pass to the function.
- **function** (string) **(required)**: A JavaScript function to run in the currently selected page.
Example without arguments: `() => {
Example without arguments: `() => {
return document.title
}` or `async () => {
return await fetch("example.com")
}`.
Example with arguments: `(el) => {
Example with arguments: `(el) => {
return el.innerText;
}`


---

### `list_console_messages`
Expand Down
4 changes: 3 additions & 1 deletion src/McpContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,9 @@ export class McpContext implements Context {
*/
async createTextSnapshot(): Promise<void> {
const page = this.getSelectedPage();
const rootNode = await page.accessibility.snapshot();
const rootNode = await page.accessibility.snapshot({
includeIframes: true,
});
if (!rootNode) {
return;
}
Expand Down
11 changes: 7 additions & 4 deletions src/tools/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ export const waitFor = defineTool({
},
handler: async (request, response, context) => {
const page = context.getSelectedPage();
const frames = page.frames();

await Locator.race([
page.locator(`aria/${request.params.text}`),
page.locator(`text/${request.params.text}`),
]).wait();
const locators = frames.flatMap(frame => [
Comment thread
OrKoN marked this conversation as resolved.
frame.locator(`aria/${request.params.text}`),
frame.locator(`text/${request.params.text}`),
]);

await Locator.race(locators).wait();

response.appendResponseLine(
`Element with text "${request.params.text}" found.`,
Expand Down
27 changes: 27 additions & 0 deletions tests/tools/snapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,32 @@ describe('snapshot', () => {
assert.ok(response.includeSnapshot);
});
});

it('should work with iframe content', async () => {
await withBrowser(async (response, context) => {
const page = await context.getSelectedPage();

await page.setContent(
html`<h1>Top level</h1>
<iframe srcdoc="<p>Hello iframe</p>"></iframe>`,
);

await waitFor.handler(
{
params: {
text: 'Hello iframe',
},
},
response,
context,
);

assert.equal(
response.responseLines[0],
'Element with text "Hello iframe" found.',
);
assert.ok(response.includeSnapshot);
});
});
});
});
Loading