Skip to content

Commit

Permalink
fix(webdriver): wait for response if the response has not completed o…
Browse files Browse the repository at this point in the history
…nce navigation has finished (#12018)
  • Loading branch information
OrKoN committed Feb 29, 2024
1 parent 11a6d7e commit 6d8831a
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions packages/puppeteer-core/src/bidi/Frame.ts
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

0 comments on commit 6d8831a

Please sign in to comment.