Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(webdriver): wait for response if the response has not completed once navigation has finished #12018

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 30 additions & 2 deletions packages/puppeteer-core/src/bidi/Frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import {debugError, fromEmitterEvent, timeout} from '../common/util.js';

import {BidiCdpSession} from './CDPSession.js';
import type {BrowsingContext} from './core/BrowsingContext.js';
import type {Navigation} from './core/Navigation.js';
import type {Request} from './core/Request.js';
import {BidiDeserializer} from './Deserializer.js';
import {BidiDialog} from './Dialog.js';
import type {BidiElementHandle} from './ElementHandle.js';
Expand Down Expand Up @@ -360,8 +362,34 @@ export class BidiFrame extends Frame {
})
)
),
map(() => {
return navigation;
switchMap(() => {
if (navigation.request) {
function requestFinished$(
request: Request
): Observable<Navigation> {
// Reduces flakiness if the response events arrive after
// the load event.
// Usually, the response or error is already there at this point.
if (request.response || request.error) {
return of(navigation);
}
if (request.redirect) {
return requestFinished$(request.redirect);
}
return fromEmitterEvent(request, 'success')
.pipe(
raceWith(fromEmitterEvent(request, 'error')),
raceWith(fromEmitterEvent(request, 'redirect'))
)
.pipe(
switchMap(() => {
return requestFinished$(request);
})
);
}
return requestFinished$(navigation.request);
}
return of(navigation);
})
);
})
Expand Down