mirror of
https://github.com/ChromeDevTools/chrome-devtools-mcp.git
synced 2026-09-28 11:22:57 +08:00
fix: timout in WaitForHelper.ts (#2772)
This fixes two issues: - Timer would start too early and could timeout before the navigation begin. Clean up is handled by the AbortController - Cross process navigation can be slow on Windows, we started from `about:blank` to `http://127.0.0.1`
This commit is contained in:
@@ -212,7 +212,7 @@ export class WaitForHelper {
|
||||
// If no navigation occurs, this.#abortController will cancel it in the finally block.
|
||||
const navigationFinished = this.#page
|
||||
.waitForNavigation({
|
||||
timeout: options?.timeout ?? this.#navigationTimeout,
|
||||
timeout: 0,
|
||||
signal: this.#abortController.signal,
|
||||
ignoreSameDocumentNavigation: true,
|
||||
})
|
||||
@@ -253,7 +253,10 @@ export class WaitForHelper {
|
||||
// Only await navigation if one was actually initiated; otherwise, the
|
||||
// pending waitForNavigation promise will be cancelled when this.#abortController aborts.
|
||||
if (navigationStarted) {
|
||||
await navigationFinished;
|
||||
await Promise.race([
|
||||
navigationFinished,
|
||||
this.timeout(options?.timeout ?? this.#navigationTimeout),
|
||||
]);
|
||||
}
|
||||
|
||||
if (this.#dialogDetected) {
|
||||
|
||||
@@ -891,8 +891,9 @@ describe('pages', () => {
|
||||
|
||||
it('respects the timeout parameter', async () => {
|
||||
await withMcpContext(async (response, context, args) => {
|
||||
const page = context.getSelectedMcpPage().pptrPage;
|
||||
const stub = sinon.stub(page, 'waitForNavigation').resolves(null);
|
||||
const mcpPage = context.getSelectedMcpPage();
|
||||
const waitForEventsSpy = sinon.spy(mcpPage, 'waitForEventsAfterAction');
|
||||
const gotoSpy = sinon.spy(mcpPage.pptrPage, 'goto');
|
||||
|
||||
try {
|
||||
await navigatePage(args).handler(
|
||||
@@ -901,19 +902,25 @@ describe('pages', () => {
|
||||
url: 'data:text/html,<html></html>',
|
||||
timeout: 12345,
|
||||
},
|
||||
page: context.getSelectedMcpPage(),
|
||||
page: mcpPage,
|
||||
},
|
||||
response,
|
||||
context,
|
||||
);
|
||||
} finally {
|
||||
stub.restore();
|
||||
waitForEventsSpy.restore();
|
||||
gotoSpy.restore();
|
||||
}
|
||||
|
||||
sinon.assert.calledOnceWithExactly(
|
||||
gotoSpy,
|
||||
'data:text/html,<html></html>',
|
||||
{timeout: 12345},
|
||||
);
|
||||
assert.strictEqual(
|
||||
stub.firstCall.args[0]?.timeout,
|
||||
waitForEventsSpy.firstCall.args[1]?.timeout,
|
||||
12345,
|
||||
'The timeout parameter should be passed to waitForNavigation',
|
||||
'The timeout parameter should be passed to waitForEventsAfterAction',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -53,9 +53,12 @@ describe('WaitForHelper', () => {
|
||||
|
||||
it('awaits navigation when action takes longer than expectNavigationIn', async () => {
|
||||
await withMcpContext(async (response, context) => {
|
||||
server.addHtmlRoute('/nav-initial', html`<main>initial</main>`);
|
||||
server.addHtmlRoute('/nav-target', html`<main>navigated</main>`);
|
||||
const startUrl = server.getRoute('/nav-initial');
|
||||
const url = server.getRoute('/nav-target');
|
||||
const mcpPage = context.getSelectedMcpPage();
|
||||
await mcpPage.pptrPage.goto(startUrl);
|
||||
|
||||
const result = await mcpPage.waitForEventsAfterAction(
|
||||
async () => {
|
||||
|
||||
Reference in New Issue
Block a user