puppeteer/test/assets/websocket.html
Patrick Hulce 4b0b81fd9b Add better network idle definition (#38)
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
2017-06-28 14:39:37 -07:00

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>