Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions packages/playwright-core/src/tools/backend/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ const resume = defineTool({
}
};
browserContext.debugger.on('pausedstatechanged', listener);
browserContext.once('close', () => {
browserContext.debugger.off('pausedstatechanged', listener);
resolve();
});
});

if (params.location) {
Expand Down
23 changes: 23 additions & 0 deletions tests/mcp/devtools.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,29 @@ test('browser_hide_highlight', async ({ boundBrowser, startClient }) => {
await expect(page.locator('x-pw-highlight')).toHaveCount(0);
});

test('browser_resume completes when context closes', async ({ boundBrowser, startClient }) => {
const page = await boundBrowser.newPage();
await page.setContent(`<button>Submit</button>`);
const context = boundBrowser.contexts()[0];

// Pause the debugger before the next action.
await context.debugger.requestPause();
const clickPromise = page.click('button');
await new Promise<void>(resolve => context.debugger.once('pausedstatechanged', resolve));
expect(context.debugger.pausedDetails()).toBeTruthy();

// browser_resume without step or location resumes execution and
// waits for either the next pause or context close. Closing the
// context after resume simulates a test finishing with no further
// breakpoints. Before the fix, this would hang indefinitely.
const { client } = await startClient({ args: [`--endpoint=default`] });
const resumePromise = client.callTool({ name: 'browser_resume' });

await clickPromise;
await context.close();
await resumePromise;
});

test('browser_hide_highlight all', async ({ boundBrowser, startClient }) => {
const page = await boundBrowser.newPage();
await page.setContent(`<button>Submit</button><a href="#">Go</a>`);
Expand Down
Loading