@@ -253,3 +253,51 @@ it.describe(() => {
253253 expect ( await page . evaluate ( async ( ) => ( await ( window as any ) . queryLocalFonts ( ) ) . length > 0 ) ) . toBe ( true ) ;
254254 } ) ;
255255} ) ;
256+
257+ it ( 'local network request is allowed from public origin' , {
258+ annotation : { type : 'issue' , description : 'https://github.com/microsoft/playwright/issues/37861' }
259+ } , async ( { page, context, server, browserName } ) => {
260+ it . fail ( browserName === 'webkit' ) ;
261+ if ( browserName === 'chromium' )
262+ await context . grantPermissions ( [ 'local-network-access' ] ) ;
263+ const serverRequests = [ ] ;
264+ server . setRoute ( '/cors' , ( req , res ) => {
265+ serverRequests . push ( `${ req . method } ${ req . url } ` ) ;
266+ if ( req . method === 'OPTIONS' ) {
267+ res . writeHead ( 204 , {
268+ 'Access-Control-Allow-Origin' : '*' ,
269+ 'Access-Control-Allow-Methods' : 'GET, POST, PUT, OPTIONS' ,
270+ 'Access-Control-Allow-Headers' : '*' ,
271+ } ) ;
272+ res . end ( ) ;
273+ return ;
274+ }
275+ res . writeHead ( 200 , { 'Content-type' : 'text/plain' , 'Access-Control-Allow-Origin' : '*' } ) ;
276+ res . end ( 'Hello there!' ) ;
277+ } ) ;
278+ const clientRequests = [ ] ;
279+ // Has to be a public origin.
280+ await page . goto ( 'https://demo.playwright.dev/todomvc/' ) ;
281+ page . on ( 'request' , request => {
282+ clientRequests . push ( `${ request . method ( ) } ${ request . url ( ) } ` ) ;
283+ } ) ;
284+ const response = await page . evaluate ( async url => {
285+ const response = await fetch ( url , {
286+ method : 'POST' ,
287+ body : '' ,
288+ headers : {
289+ 'Content-Type' : 'application/json' ,
290+ 'X-Custom-Header' : 'test-value'
291+ }
292+ } ) ;
293+ return await response . text ( ) ;
294+ } , server . CROSS_PROCESS_PREFIX + '/cors' ) . catch ( e => e . message ) ;
295+ expect ( response ) . toBe ( 'Hello there!' ) ;
296+ expect ( serverRequests ) . toEqual ( [
297+ 'OPTIONS /cors' ,
298+ 'POST /cors' ,
299+ ] ) ;
300+ expect ( clientRequests ) . toEqual ( [
301+ `POST ${ server . CROSS_PROCESS_PREFIX } /cors` ,
302+ ] ) ;
303+ } ) ;
0 commit comments