@@ -428,10 +428,12 @@ playwright.chromium.launch().then(async browser => {
428428 {
429429 await locator . evaluateAll ( ( sel : HTMLSelectElement [ ] ) => { } )
430430 }
431+ // Handles in callback results are unboxed, but the callback keeps its authored
432+ // sync/async signature, even though the runtime always exposes it as async on the page side.
431433 {
432434 await locator . evaluate ( ( e , cb ) => {
433435 const value = cb ( 2 ) ;
434- const assertion : AssertType < Promise < number > , typeof value > = true ;
436+ const assertion : AssertType < number , typeof value > = true ;
435437 } , ( x : number ) => 2 * x ) ;
436438 }
437439 {
@@ -456,6 +458,54 @@ playwright.chromium.launch().then(async browser => {
456458 const assertion : AssertType < Promise < { double : number , add : number } > , typeof value > = true ;
457459 } , { cb : func } ) ;
458460 }
461+ {
462+ // Promises nested in the argument are not awaited, only callback results are.
463+ const result = await page . evaluate ( arg => {
464+ const assertion : AssertType < Promise < number > , typeof arg . a > = true ;
465+ return arg ;
466+ } , { a : new Promise < number > ( ( ) => { } ) , b : 42 } ) ;
467+ const assertion : AssertType < { a : Promise < number > , b : number } , typeof result > = true ;
468+ }
469+ await browser . close ( ) ;
470+ } ) ( ) ;
471+
472+ // branded primitives in evaluate arguments — https://github.com/microsoft/playwright/issues/42000
473+ declare const __brand : unique symbol ;
474+ type Branded < T , B > = T & { [ __brand ] : B } ;
475+ type IsoDate = Branded < string , 'IsoDate' > ;
476+ declare function takesIsoDate ( date : IsoDate ) : void ;
477+
478+ ( async ( ) => {
479+ const browser = await playwright . chromium . launch ( ) ;
480+ const page = await browser . newPage ( ) ;
481+ const date = '2026-01-15' as IsoDate ;
482+ {
483+ const result = await page . evaluate ( ( d : IsoDate ) => d , date ) ;
484+ const assertion : AssertType < IsoDate , typeof result > = true ;
485+ }
486+ {
487+ await page . evaluate ( d => takesIsoDate ( d ) , date ) ;
488+ }
489+ {
490+ await page . evaluate ( ( { d } ) => takesIsoDate ( d ) , { d : date } ) ;
491+ }
492+ {
493+ const count = 42 as Branded < number , 'Count' > ;
494+ const result = await page . evaluate ( c => c , count ) ;
495+ const assertion : AssertType < Branded < number , 'Count' > , typeof result > = true ;
496+ }
497+ {
498+ const result = await page . evaluate ( ( arg : { d ?: IsoDate } ) => arg . d , { d : date } as { d ?: IsoDate } ) ;
499+ const assertion : AssertType < IsoDate | undefined , typeof result > = true ;
500+ }
501+ {
502+ const result = await page . evaluate ( ( dates : readonly IsoDate [ ] ) => dates [ 0 ] , [ date ] as readonly IsoDate [ ] ) ;
503+ const assertion : AssertType < IsoDate , typeof result > = true ;
504+ }
505+ {
506+ const result = await page . evaluate ( ( pair : [ IsoDate , number ] ) => pair [ 0 ] , [ date , 42 ] as [ IsoDate , number ] ) ;
507+ const assertion : AssertType < IsoDate , typeof result > = true ;
508+ }
459509 await browser . close ( ) ;
460510} ) ( ) ;
461511
0 commit comments