11import { isDeepStrictEqual } from 'node:util' ;
2- import puppeteer from 'puppeteer' ;
2+ import { launch , type Page } from 'puppeteer' ;
33import { delay } from 'unicorn-magic' ;
44import { type SpeedData , type SpeedUnit } from './types.js' ;
55
66type Options = {
77 measureUpload ?: boolean ;
88} ;
99
10- async function * monitorSpeed ( page : puppeteer . Page , options ?: Options ) : AsyncGenerator < SpeedData , void , undefined > {
10+ async function * monitorSpeed ( page : Page , options ?: Options ) : AsyncGenerator < SpeedData , void , undefined > {
1111 let previousResult : SpeedData | undefined ;
1212
1313 while ( true ) {
@@ -25,6 +25,7 @@ async function * monitorSpeed(page: puppeteer.Page, options?: Options): AsyncGen
2525 latency : Number ( $ ( '#latency-value' ) ?. textContent ?. trim ( ) ) || 0 ,
2626 bufferBloat : Number ( $ ( '#bufferbloat-value' ) ?. textContent ?. trim ( ) ) || 0 ,
2727 userLocation : $ ( '#user-location' ) ?. textContent ?. trim ( ) ?? '' ,
28+ serverLocations : $ ( '#server-locations' ) ?. textContent ?. split ( '|' ) . map ( location => location . trim ( ) ) . filter ( Boolean ) ?? [ ] ,
2829 userIp : $ ( '#user-ip' ) ?. textContent ?. trim ( ) ?? '' ,
2930 isDone : Boolean ( $ ( '#speed-value.succeeded' ) && $ ( '#upload-value.succeeded' ) ) ,
3031 } ;
@@ -46,7 +47,7 @@ async function * monitorSpeed(page: puppeteer.Page, options?: Options): AsyncGen
4647}
4748
4849export default async function * api ( options ?: Options ) : AsyncGenerator < SpeedData , void , undefined > {
49- const browser = await puppeteer . launch ( {
50+ const browser = await launch ( {
5051 args : [ '--no-sandbox' , '--disable-setuid-sandbox' , '--disable-dev-shm-usage' ] ,
5152 headless : true ,
5253 } ) ;
0 commit comments