2929Console . WriteLine ( ) ;
3030
3131const string playwrightPath = "playwright-dotnet" ;
32- var driverVersion = args . Length > 0 ? args [ 0 ] : null ;
33- var packageVersion = args . Length > 1 ? args [ 1 ] : null ;
32+ var isolatedContextDefaultValue = args . Length > 0 ? bool . Parse ( args [ 0 ] ) : true ;
33+ var driverVersion = args . Length > 1 ? args [ 1 ] : null ;
34+ var packageVersion = args . Length > 2 ? args [ 2 ] : null ;
3435
3536if ( ! Directory . Exists ( playwrightPath ) )
3637{
@@ -270,14 +271,14 @@ void PatchWorker()
270271
271272 Console . WriteLine ( $"Patching Worker file: {workerPath}" ) ;
272273
273- File . WriteAllText ( workerPath , AddIsolatedContextToMethods ( workerCode , "Worker" , methodNamesToPatch ) ) ;
274+ File . WriteAllText ( workerPath , AddIsolatedContextToMethods ( workerCode , "Worker" , isolatedContextDefaultValue , methodNamesToPatch ) ) ;
274275
275276 var workerGeneratedInterfacePath = Path. Combine( playwrightPath , "src" , "Playwright" , "API" , "Generated" , "IWorker.cs" ) ;
276277 var workerGeneratedInterfaceCode = File. ReadAllText( workerGeneratedInterfacePath ) ;
277278
278279 Console . WriteLine( $"Patching generated IWorker file: {workerGeneratedInterfacePath}" ) ;
279280
280- File . WriteAllText ( workerGeneratedInterfacePath , AddIsolatedContextToMethods ( workerGeneratedInterfaceCode , "IWorker" , methodNamesToPatch ) ) ;
281+ File . WriteAllText ( workerGeneratedInterfacePath , AddIsolatedContextToMethods ( workerGeneratedInterfaceCode , "IWorker" , isolatedContextDefaultValue , methodNamesToPatch ) ) ;
281282}
282283
283284// Add isolatedContext parameter to JSHandle methods.
@@ -290,21 +291,21 @@ void PatchJSHandle()
290291
291292 Console . WriteLine( $"Patching JSHandle file: {jsHandlePath}" ) ;
292293
293- File . WriteAllText ( jsHandlePath , AddIsolatedContextToMethods ( jsHandleCode , "JSHandle" , methodNamesToPatch ) ) ;
294+ File . WriteAllText ( jsHandlePath , AddIsolatedContextToMethods ( jsHandleCode , "JSHandle" , isolatedContextDefaultValue , methodNamesToPatch ) ) ;
294295
295296 var jsHandleGeneratedInterfacePath = Path. Combine( playwrightPath , "src" , "Playwright" , "API" , "Generated" , "IJSHandle.cs" ) ;
296297 var jsHandleGeneratedInterfaceCode = File. ReadAllText( jsHandleGeneratedInterfacePath ) ;
297298
298299 Console . WriteLine( $"Patching generated IJSHandle file: {jsHandleGeneratedInterfacePath}" ) ;
299300
300- File . WriteAllText ( jsHandleGeneratedInterfacePath , AddIsolatedContextToMethods ( jsHandleGeneratedInterfaceCode , "IJSHandle" , methodNamesToPatch ) ) ;
301+ File . WriteAllText ( jsHandleGeneratedInterfacePath , AddIsolatedContextToMethods ( jsHandleGeneratedInterfaceCode , "IJSHandle" , isolatedContextDefaultValue , methodNamesToPatch ) ) ;
301302
302303 var jsHandleSupplementsInterfacePath = Path. Combine( playwrightPath , "src" , "Playwright" , "API" , "Supplements" , "IJSHandle.cs" ) ;
303304 var jsHandleSupplementsInterfaceCode = File. ReadAllText( jsHandleSupplementsInterfacePath ) ;
304305
305306 Console . WriteLine( $"Patching supplements IJSHandle file: {jsHandleSupplementsInterfacePath}" ) ;
306307
307- var newJsHandleSupplementsInterfaceCode = AddIsolatedContextToMethods( jsHandleSupplementsInterfaceCode , "IJSHandle" , methodNamesToPatch ) ;
308+ var newJsHandleSupplementsInterfaceCode = AddIsolatedContextToMethods( jsHandleSupplementsInterfaceCode , "IJSHandle" , isolatedContextDefaultValue , methodNamesToPatch ) ;
308309 File . WriteAllText ( jsHandleSupplementsInterfacePath , newJsHandleSupplementsInterfaceCode . Replace ( "EvaluateAsync{T}(string, object)" , "EvaluateAsync{T}(string, object, bool)" ) ) ;
309310}
310311
@@ -319,21 +320,21 @@ void PatchFrame()
319320
320321 Console . WriteLine( $"Patching Frame file: {framePath}" ) ;
321322
322- File . WriteAllText ( framePath , AddIsolatedContextToMethods ( frameCode , "Frame" , methodNamesToPatch ) ) ;
323+ File . WriteAllText ( framePath , AddIsolatedContextToMethods ( frameCode , "Frame" , isolatedContextDefaultValue , methodNamesToPatch ) ) ;
323324
324325 var frameGeneratedInterfacePath = Path. Combine( playwrightPath , "src" , "Playwright" , "API" , "Generated" , "IFrame.cs" ) ;
325326 var frameGeneratedInterfaceCode = File. ReadAllText( frameGeneratedInterfacePath ) ;
326327
327328 Console . WriteLine( $"Patching generated IFrame file: {frameGeneratedInterfacePath}" ) ;
328329
329- File . WriteAllText ( frameGeneratedInterfacePath , AddIsolatedContextToMethods ( frameGeneratedInterfaceCode , "IFrame" , methodNamesToPatch ) ) ;
330+ File . WriteAllText ( frameGeneratedInterfacePath , AddIsolatedContextToMethods ( frameGeneratedInterfaceCode , "IFrame" , isolatedContextDefaultValue , methodNamesToPatch ) ) ;
330331
331332 var frameSupplementsInterfacePath = Path. Combine( playwrightPath , "src" , "Playwright" , "API" , "Supplements" , "IFrame.cs" ) ;
332333 var frameSupplementsInterfaceCode = File. ReadAllText( frameSupplementsInterfacePath ) ;
333334
334335 Console . WriteLine( $"Patching supplements IFrame file: {frameSupplementsInterfacePath}" ) ;
335336
336- File . WriteAllText ( frameSupplementsInterfacePath , AddIsolatedContextToMethods ( frameSupplementsInterfaceCode , "IFrame" , methodNamesToPatch ) ) ;
337+ File . WriteAllText ( frameSupplementsInterfacePath , AddIsolatedContextToMethods ( frameSupplementsInterfaceCode , "IFrame" , isolatedContextDefaultValue , methodNamesToPatch ) ) ;
337338}
338339
339340// Add isolatedContext parameter to Locator methods.
@@ -346,21 +347,21 @@ void PatchLocator()
346347
347348 Console . WriteLine( $"Patching Locator file: {locatorPath}" ) ;
348349
349- File . WriteAllText ( locatorPath , AddIsolatedContextToMethods ( locatorCode , "Locator" , methodNamesToPatch ) ) ;
350+ File . WriteAllText ( locatorPath , AddIsolatedContextToMethods ( locatorCode , "Locator" , isolatedContextDefaultValue , methodNamesToPatch ) ) ;
350351
351352 var locatorGeneratedInterfacePath = Path. Combine( playwrightPath , "src" , "Playwright" , "API" , "Generated" , "ILocator.cs" ) ;
352353 var locatorGeneratedInterfaceCode = File. ReadAllText( locatorGeneratedInterfacePath ) ;
353354
354355 Console . WriteLine( $"Patching generated ILocator file: {locatorGeneratedInterfacePath}" ) ;
355356
356- File . WriteAllText ( locatorGeneratedInterfacePath , AddIsolatedContextToMethods ( locatorGeneratedInterfaceCode , "ILocator" , methodNamesToPatch ) ) ;
357+ File . WriteAllText ( locatorGeneratedInterfacePath , AddIsolatedContextToMethods ( locatorGeneratedInterfaceCode , "ILocator" , isolatedContextDefaultValue , methodNamesToPatch ) ) ;
357358
358359 var locatorSupplementsInterfacePath = Path. Combine( playwrightPath , "src" , "Playwright" , "API" , "Supplements" , "ILocator.cs" ) ;
359360 var locatorSupplementsInterfaceCode = File. ReadAllText( locatorSupplementsInterfacePath ) ;
360361
361362 Console . WriteLine( $"Patching supplements ILocator file: {locatorSupplementsInterfacePath}" ) ;
362363
363- File . WriteAllText ( locatorSupplementsInterfacePath , AddIsolatedContextToMethods ( locatorSupplementsInterfaceCode , "ILocator" , methodNamesToPatch ) ) ;
364+ File . WriteAllText ( locatorSupplementsInterfacePath , AddIsolatedContextToMethods ( locatorSupplementsInterfaceCode , "ILocator" , isolatedContextDefaultValue , methodNamesToPatch ) ) ;
364365}
365366
366367// Add isolatedContext parameter to Page methods.
@@ -373,7 +374,7 @@ void PatchPage()
373374
374375 Console . WriteLine( $"Patching Page file: {pagePath}" ) ;
375376
376- File . WriteAllText ( pagePath , AddIsolatedContextToMethods ( pageCode , "Page" , methodNamesToPatch ) ) ;
377+ File . WriteAllText ( pagePath , AddIsolatedContextToMethods ( pageCode , "Page" , isolatedContextDefaultValue , methodNamesToPatch ) ) ;
377378
378379 // Read the code again after the isolated context changes have been applied.
379380 pageCode = File . ReadAllText ( pagePath ) ;
@@ -456,14 +457,14 @@ await RouteAsync("**/*", async route =>
456457
457458 Console. WriteLine ( $ "Patching generated IPage file: { pageGeneratedInterfacePath } ") ;
458459
459- File. WriteAllText ( pageGeneratedInterfacePath , AddIsolatedContextToMethods ( pageGeneratedInterfaceCode , "IPage" , methodNamesToPatch ) ) ;
460+ File. WriteAllText ( pageGeneratedInterfacePath , AddIsolatedContextToMethods ( pageGeneratedInterfaceCode , "IPage" , isolatedContextDefaultValue , methodNamesToPatch ) ) ;
460461
461462 var pageSupplementsInterfacePath = Path. Combine ( playwrightPath , "src" , "Playwright" , "API" , "Supplements" , "IPage.cs" ) ;
462463 var pageSupplementsInterfaceCode = File. ReadAllText ( pageSupplementsInterfacePath ) ;
463464
464465 Console. WriteLine ( $ "Patching supplements IPage file: { pageSupplementsInterfacePath } ") ;
465466
466- File. WriteAllText ( pageSupplementsInterfacePath , AddIsolatedContextToMethods ( pageSupplementsInterfaceCode , "IPage" , methodNamesToPatch ) ) ;
467+ File. WriteAllText ( pageSupplementsInterfacePath , AddIsolatedContextToMethods ( pageSupplementsInterfaceCode , "IPage" , isolatedContextDefaultValue , methodNamesToPatch ) ) ;
467468}
468469
469470// Add route injection to BrowserContext class and call from relevant methods.
@@ -870,7 +871,7 @@ inv.Expression is SimpleNameSyntax simpleName &&
870871
871872// Method to add isolatedContext parameter to specified methods provided.
872873// This will also patch pass-through calls to private methods as needed and add the dictionary entry to SendMessageToServerAsync calls.
873- static string AddIsolatedContextToMethods( string code , string typeName , IEnumerable < string > methodNames )
874+ static string AddIsolatedContextToMethods( string code , string typeName , bool defaultValue , IEnumerable < string > methodNames )
874875{
875876 var tree = CSharpSyntaxTree. ParseText ( code ) ;
876877 var root = tree. GetRoot ( ) ;
@@ -1011,7 +1012,7 @@ static string AddIsolatedContextToMethods(string code, string typeName, IEnumera
10111012 SyntaxFactory. Token( SyntaxKind. EqualsToken)
10121013 . WithLeadingTrivia( SyntaxFactory. Space)
10131014 . WithTrailingTrivia( SyntaxFactory. Space) ,
1014- SyntaxFactory . LiteralExpression ( SyntaxKind . TrueLiteralExpression ) ) ) ;
1015+ defaultValue ? SyntaxFactory . LiteralExpression( SyntaxKind . TrueLiteralExpression ) : SyntaxFactory . LiteralExpression ( SyntaxKind . FalseLiteralExpression ) ) ) ;
10151016
10161017 // Add leading space if there are existing parameters.
10171018 var newParameterList = currentMethod. ParameterList. Parameters. Count > 0
0 commit comments