mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix: waitForNavigation issue with aborted events (#9883)
This commit is contained in:
parent
3ea15dc395
commit
36c029b38d
@ -302,11 +302,7 @@ export class NetworkManager extends EventEmitter {
|
||||
}
|
||||
|
||||
#onAuthRequired(event: Protocol.Fetch.AuthRequiredEvent): void {
|
||||
/* TODO(jacktfranklin): This is defined in protocol.d.ts but not
|
||||
* in an easily referrable way - we should look at exposing it.
|
||||
*/
|
||||
type AuthResponse = 'Default' | 'CancelAuth' | 'ProvideCredentials';
|
||||
let response: AuthResponse = 'Default';
|
||||
let response: Protocol.Fetch.AuthChallengeResponse['response'] = 'Default';
|
||||
if (this.#attemptedAuthentications.has(event.requestId)) {
|
||||
response = 'CancelAuth';
|
||||
} else if (this.#credentials) {
|
||||
|
@ -991,10 +991,7 @@ export class CDPPage extends Page {
|
||||
|
||||
const networkManager = this.#frameManager.networkManager;
|
||||
|
||||
let idleResolveCallback: () => void;
|
||||
const idlePromise = new Promise<void>(resolve => {
|
||||
idleResolveCallback = resolve;
|
||||
});
|
||||
const idlePromise = createDeferredPromise<void>();
|
||||
|
||||
let abortRejectCallback: (error: Error) => void;
|
||||
const abortPromise = new Promise<Error>((_, reject) => {
|
||||
@ -1002,10 +999,6 @@ export class CDPPage extends Page {
|
||||
});
|
||||
|
||||
let idleTimer: NodeJS.Timeout;
|
||||
const onIdle = () => {
|
||||
return idleResolveCallback();
|
||||
};
|
||||
|
||||
const cleanup = () => {
|
||||
idleTimer && clearTimeout(idleTimer);
|
||||
abortRejectCallback(new Error('abort'));
|
||||
@ -1014,7 +1007,7 @@ export class CDPPage extends Page {
|
||||
const evaluate = () => {
|
||||
idleTimer && clearTimeout(idleTimer);
|
||||
if (networkManager.numRequestsInProgress() === 0) {
|
||||
idleTimer = setTimeout(onIdle, idleTime);
|
||||
idleTimer = setTimeout(idlePromise.resolve, idleTime);
|
||||
}
|
||||
};
|
||||
|
||||
@ -1038,6 +1031,7 @@ export class CDPPage extends Page {
|
||||
const eventPromises = [
|
||||
listenToEvent(NetworkManagerEmittedEvents.Request),
|
||||
listenToEvent(NetworkManagerEmittedEvents.Response),
|
||||
listenToEvent(NetworkManagerEmittedEvents.RequestFailed),
|
||||
];
|
||||
|
||||
await Promise.race([
|
||||
|
13
test/assets/abort-request.html
Normal file
13
test/assets/abort-request.html
Normal file
@ -0,0 +1,13 @@
|
||||
<button id="abort"></button>
|
||||
|
||||
<script>
|
||||
const button = document.getElementById('abort');
|
||||
button.addEventListener('click', getJson)
|
||||
async function getJson() {
|
||||
const abort = new AbortController();
|
||||
const result = fetch("/simple.json", {
|
||||
signal: abort.signal
|
||||
});
|
||||
abort.abort();
|
||||
}
|
||||
</script>
|
@ -1163,6 +1163,21 @@ describe('Page', function () {
|
||||
]);
|
||||
expect(result).toBe(undefined);
|
||||
});
|
||||
it('should work with aborted requests', async () => {
|
||||
const {page, server} = getTestState();
|
||||
|
||||
await page.goto(server.PREFIX + '/abort-request.html');
|
||||
|
||||
const element = await page.$(`#abort`);
|
||||
await element!.click();
|
||||
|
||||
let error = false;
|
||||
await page.waitForNetworkIdle().catch(() => {
|
||||
return (error = true);
|
||||
});
|
||||
|
||||
expect(error).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Page.exposeFunction', function () {
|
||||
|
Loading…
Reference in New Issue
Block a user