Skip to content

Commit af249c2

Browse files
committed
fix: create initial page in BrowserContext sessions
BrowserContext starts with zero pages, so createSession() must call newPage() after creating the McpContext. Also reorders viewport before navigation for correct initial layout.
1 parent f5ad237 commit af249c2

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

src/SessionManager.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,18 @@ export class SessionManager {
7878
contextOptions,
7979
);
8080

81-
if (options.url) {
82-
const page = context.getSelectedPage();
83-
await page.goto(options.url, {waitUntil: 'load'});
84-
}
81+
// BrowserContext starts with zero pages, so we must create an initial one.
82+
const page = await context.newPage();
8583

84+
// Set viewport before navigation for correct initial layout.
8685
if (options.viewport) {
87-
const page = context.getSelectedPage();
8886
await page.setViewport(options.viewport);
8987
}
9088

89+
if (options.url) {
90+
await page.goto(options.url, {waitUntil: 'load'});
91+
}
92+
9193
const session: Session = {
9294
sessionId,
9395
label: options.label,

0 commit comments

Comments
 (0)