mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
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>
|