4b0b81fd9b
This patch: - Changes network idle promise to wait for 2 or fewer network requests for at least idleTime (defaults to 5s) before resolving. - Adds timer cleanup to failure navigation case. - Adds handling of webSocketClosed. - Ignores unrecognized requestIds to avoid negative inflight requests. References #10
29 lines
785 B
HTML
29 lines
785 B
HTML
<script>
|
|
function createClient() {
|
|
const client = new WebSocket(`ws://${location.host}`);
|
|
client.addEventListener('open', () => console.log('opened'));
|
|
client.addEventListener('close', () => console.log('closed'));
|
|
return client;
|
|
}
|
|
|
|
function createAndDestroyClientAfterDelay(delay = 50) {
|
|
const client = createClient();
|
|
return new Promise(resolve => {
|
|
setTimeout(() => {
|
|
client.close();
|
|
resolve();
|
|
}, delay);
|
|
});
|
|
}
|
|
|
|
async function main() {
|
|
await createAndDestroyClientAfterDelay();
|
|
await createAndDestroyClientAfterDelay();
|
|
await createAndDestroyClientAfterDelay();
|
|
await createAndDestroyClientAfterDelay();
|
|
await fetch('fetch-request.js');
|
|
}
|
|
|
|
main().then(() => console.log('done!'));
|
|
</script>
|