Skip to content

Commit 37088bc

Browse files
Merge pull request #25 from yonaka15/feature/viewport-config
feat: add viewport size configuration
2 parents 19a8842 + 939affc commit 37088bc

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

Diff for: src/tools.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ export function createToolDefinitions(): Tool[] {
99
type: "object",
1010
properties: {
1111
url: { type: "string" },
12+
width: { type: "number", description: "Viewport width in pixels (default: 1920)" },
13+
height: { type: "number", description: "Viewport height in pixels (default: 1080)" },
14+
timeout: { type: "number", description: "Navigation timeout in milliseconds" },
15+
waitUntil: { type: "string", description: "Navigation wait condition" }
1216
},
1317
required: ["url"],
1418
},
@@ -159,7 +163,6 @@ export const BROWSER_TOOLS = [
159163
"playwright_evaluate"
160164
];
161165

162-
163166
// API Request tools for conditional launch
164167
export const API_TOOLS = [
165168
"playwright_get",

Diff for: src/toolsHandler.ts

+17-4
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,20 @@ const consoleLogs: string[] = [];
1212
const screenshots = new Map<string, string>();
1313
const defaultDownloadsPath = path.join(os.homedir(), 'Downloads');
1414

15-
async function ensureBrowser() {
15+
// Viewport type definition
16+
type ViewportSize = {
17+
width?: number;
18+
height?: number;
19+
};
20+
21+
async function ensureBrowser(viewport?: ViewportSize) {
1622
if (!browser) {
1723
browser = await chromium.launch({ headless: false });
1824
const context = await browser.newContext({
19-
viewport: { width: 1920, height: 1080 },
25+
viewport: {
26+
width: viewport?.width ?? 1920,
27+
height: viewport?.height ?? 1080,
28+
},
2029
deviceScaleFactor: 1,
2130
});
2231

@@ -51,7 +60,10 @@ export async function handleToolCall(
5160

5261
// Only launch browser if the tool requires browser interaction
5362
if (requiresBrowser) {
54-
page = await ensureBrowser();
63+
page = await ensureBrowser({
64+
width: args.width,
65+
height: args.height
66+
});
5567
}
5668

5769
// Set up API context for API-related operations
@@ -70,7 +82,8 @@ export async function handleToolCall(
7082
toolResult: {
7183
content: [{
7284
type: "text",
73-
text: `Navigated to ${args.url} with ${args.waitUntil || "load"} wait`,
85+
text: `Navigated to ${args.url} with ${args.waitUntil || "load"} wait` +
86+
(args.width && args.height ? ` (viewport: ${args.width}x${args.height})` : ""),
7487
}],
7588
isError: false,
7689
},

0 commit comments

Comments
 (0)