@@ -126,64 +126,54 @@ describe('browser', () => {
126126 assert . strictEqual ( content , 'Allowed' ) ;
127127
128128 // Fetch of blocked URL from the page
129- const fetchResult = await page . evaluate ( async url => {
129+ const fetchSucceeded = await page . evaluate ( async url => {
130130 try {
131131 await fetch ( url ) ;
132- return 'SUCCESS' ;
133- } catch ( err ) {
134- return err instanceof Error ? err . message : String ( err ) ;
132+ return true ;
133+ } catch {
134+ return false ;
135135 }
136136 } , server . getRoute ( '/blocked.html' ) ) ;
137137
138- assert . strictEqual ( fetchResult , 'Failed to fetch' ) ;
138+ assert . strictEqual ( fetchSucceeded , false ) ;
139139 } finally {
140140 await browser . close ( ) ;
141141 }
142142 } ) ;
143143
144- it (
145- 'blocks URLs not in allowlist' ,
146- { skip : 'Requires Chrome 149 or greater' } ,
147- async ( ) => {
148- server . addHtmlRoute (
149- '/allowed.html' ,
150- '<html><body>Allowed</body></html>' ,
151- ) ;
152- server . addHtmlRoute (
153- '/blocked.html' ,
154- '<html><body>Blocked</body></html>' ,
155- ) ;
144+ it ( 'blocks URLs not in allowlist' , async ( ) => {
145+ server . addHtmlRoute ( '/allowed.html' , '<html><body>Allowed</body></html>' ) ;
146+ server . addHtmlRoute ( '/blocked.html' , '<html><body>Blocked</body></html>' ) ;
156147
157- const browser = await launch ( {
158- headless : true ,
159- isolated : true ,
160- executablePath : await executablePath ( ) ,
161- devtools : false ,
162- allowlist : [ '*://*/allowed.html' ] ,
163- } ) ;
164- try {
165- const page = await browser . newPage ( ) ;
166-
167- // Access allowed URL
168- await page . goto ( server . getRoute ( '/allowed.html' ) ) ;
169- const content = await page . evaluate ( ( ) => document . body . textContent ) ;
170- assert . strictEqual ( content , 'Allowed' ) ;
171-
172- // Fetch of blocked URL from the page
173- const fetchResult = await page . evaluate ( async url => {
174- try {
175- await fetch ( url ) ;
176- return 'SUCCESS' ;
177- } catch ( err ) {
178- return err instanceof Error ? err . message : String ( err ) ;
179- }
180- } , server . getRoute ( '/blocked.html' ) ) ;
181-
182- assert . strictEqual ( fetchResult , 'Failed to fetch' ) ;
183- } finally {
184- await browser . close ( ) ;
185- }
186- } ,
187- ) ;
148+ const browser = await launch ( {
149+ headless : true ,
150+ isolated : true ,
151+ executablePath : await executablePath ( ) ,
152+ devtools : false ,
153+ allowlist : [ '*://*:*/allowed.html' ] ,
154+ } ) ;
155+ try {
156+ const page = await browser . newPage ( ) ;
157+
158+ // Access allowed URL
159+ await page . goto ( server . getRoute ( '/allowed.html' ) ) ;
160+ const content = await page . evaluate ( ( ) => document . body . textContent ) ;
161+ assert . strictEqual ( content , 'Allowed' ) ;
162+
163+ // Fetch of blocked URL from the page
164+ const fetchSucceeded = await page . evaluate ( async url => {
165+ try {
166+ await fetch ( url ) ;
167+ return true ;
168+ } catch {
169+ return false ;
170+ }
171+ } , server . getRoute ( '/blocked.html' ) ) ;
172+
173+ assert . strictEqual ( fetchSucceeded , false ) ;
174+ } finally {
175+ await browser . close ( ) ;
176+ }
177+ } ) ;
188178 } ) ;
189179} ) ;
0 commit comments