Skip to content

Commit 6d57cb0

Browse files
Merge pull request #124 from fwilliams96/feature/iframe-fill
feat: playwright_iframe_fill
2 parents dae228f + d451331 commit 6d57cb0

File tree

6 files changed

+58
-4
lines changed

6 files changed

+58
-4
lines changed

docs/docs/playwright-web/Supported-Tools.mdx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,17 @@ Click elements in an iframe on the page.
171171

172172
---
173173

174+
### Playwright_iframe_fill
175+
Fill elements in an iframe on the page.
176+
177+
- **`iframeSelector`** *(string)*:
178+
CSS selector for the iframe containing the element to fill.
179+
180+
- **`selector`** *(string)*:
181+
CSS selector for the element to fill.
182+
183+
---
184+
174185
### Playwright_hover
175186
Hover over elements on the page.
176187

src/__tests__/toolHandler.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ jest.mock('playwright', () => {
1515
const mockOn = jest.fn();
1616
const mockIsClosed = jest.fn().mockReturnValue(false);
1717

18-
// Mock iframe click
18+
// Mock iframe click and fill
1919
const mockIframeClick = jest.fn().mockImplementation(() => Promise.resolve());
20+
const mockIframeFill = jest.fn().mockImplementation(() => Promise.resolve());
2021
const mockIframeLocator = jest.fn().mockReturnValue({
21-
click: mockIframeClick
22+
click: mockIframeClick,
23+
fill: mockIframeFill
2224
});
23-
25+
2426
// Mock locator
2527
const mockLocatorClick = jest.fn().mockImplementation(() => Promise.resolve());
2628
const mockLocatorFill = jest.fn().mockImplementation(() => Promise.resolve());

src/toolHandler.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ import {
2525
FillTool,
2626
SelectTool,
2727
HoverTool,
28-
EvaluateTool
28+
EvaluateTool,
29+
IframeFillTool
2930
} from './tools/browser/interaction.js';
3031
import {
3132
VisibleTextTool,
@@ -73,6 +74,7 @@ let closeBrowserTool: CloseBrowserTool;
7374
let consoleLogsTool: ConsoleLogsTool;
7475
let clickTool: ClickTool;
7576
let iframeClickTool: IframeClickTool;
77+
let iframeFillTool: IframeFillTool;
7678
let fillTool: FillTool;
7779
let selectTool: SelectTool;
7880
let hoverTool: HoverTool;
@@ -310,6 +312,7 @@ function initializeTools(server: any) {
310312
if (!consoleLogsTool) consoleLogsTool = new ConsoleLogsTool(server);
311313
if (!clickTool) clickTool = new ClickTool(server);
312314
if (!iframeClickTool) iframeClickTool = new IframeClickTool(server);
315+
if (!iframeFillTool) iframeFillTool = new IframeFillTool(server);
313316
if (!fillTool) fillTool = new FillTool(server);
314317
if (!selectTool) selectTool = new SelectTool(server);
315318
if (!hoverTool) hoverTool = new HoverTool(server);
@@ -474,6 +477,9 @@ export async function handleToolCall(
474477

475478
case "playwright_iframe_click":
476479
return await iframeClickTool.execute(args, context);
480+
481+
case "playwright_iframe_fill":
482+
return await iframeFillTool.execute(args, context);
477483

478484
case "playwright_fill":
479485
return await fillTool.execute(args, context);

src/tools.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,19 @@ export function createToolDefinitions() {
133133
required: ["iframeSelector", "selector"],
134134
},
135135
},
136+
{
137+
name: "playwright_iframe_fill",
138+
description: "Fill an element in an iframe on the page",
139+
inputSchema: {
140+
type: "object",
141+
properties: {
142+
iframeSelector: { type: "string", description: "CSS selector for the iframe containing the element to fill" },
143+
selector: { type: "string", description: "CSS selector for the element to fill" },
144+
value: { type: "string", description: "Value to fill" },
145+
},
146+
required: ["iframeSelector", "selector", "value"],
147+
},
148+
},
136149
{
137150
name: "playwright_fill",
138151
description: "fill out an input field",
@@ -418,6 +431,7 @@ export const BROWSER_TOOLS = [
418431
"playwright_screenshot",
419432
"playwright_click",
420433
"playwright_iframe_click",
434+
"playwright_iframe_fill",
421435
"playwright_fill",
422436
"playwright_select",
423437
"playwright_hover",

src/tools/browser/interaction.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,26 @@ export class IframeClickTool extends BrowserToolBase {
6565
}
6666
}
6767

68+
/**
69+
* Tool for filling elements inside iframes
70+
*/
71+
export class IframeFillTool extends BrowserToolBase {
72+
/**
73+
* Execute the iframe fill tool
74+
*/
75+
async execute(args: any, context: ToolContext): Promise<ToolResponse> {
76+
return this.safeExecute(context, async (page) => {
77+
const frame = page.frameLocator(args.iframeSelector);
78+
if (!frame) {
79+
return createErrorResponse(`Iframe not found: ${args.iframeSelector}`);
80+
}
81+
82+
await frame.locator(args.selector).fill(args.value);
83+
return createSuccessResponse(`Filled element ${args.selector} inside iframe ${args.iframeSelector} with: ${args.value}`);
84+
});
85+
}
86+
}
87+
6888
/**
6989
* Tool for filling form fields
7090
*/

src/tools/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const BROWSER_TOOLS = [
88
"playwright_screenshot",
99
"playwright_click",
1010
"playwright_iframe_click",
11+
"playwright_iframe_fill",
1112
"playwright_fill",
1213
"playwright_select",
1314
"playwright_hover",

0 commit comments

Comments
 (0)