@@ -93,9 +93,14 @@ def callback_wrapper(playwright_impl: Playwright) -> None:
93
93
self ._connection .call_on_object_with_known_name ("Playwright" , callback_wrapper )
94
94
set_dispatcher_fiber (greenlet (lambda : self ._connection .run_sync ()))
95
95
dispatcher_fiber ().switch ()
96
- return self ._playwright
96
+ playwright = self ._playwright
97
+ playwright .stop = self .__exit__ # type: ignore
98
+ return playwright
97
99
98
- def __exit__ (self , exc_type : Any , exc_val : Any , exc_tb : Any ) -> None :
100
+ def start (self ) -> SyncPlaywright :
101
+ return self .__enter__ ()
102
+
103
+ def __exit__ (self , * args : Any ) -> None :
99
104
self ._connection .stop_sync ()
100
105
101
106
@@ -106,11 +111,16 @@ def __init__(self) -> None:
106
111
async def __aenter__ (self ) -> AsyncPlaywright :
107
112
self ._connection = await run_driver_async ()
108
113
self ._connection .run_async ()
109
- return AsyncPlaywright (
114
+ playwright = AsyncPlaywright (
110
115
await self ._connection .wait_for_object_with_known_name ("Playwright" )
111
116
)
117
+ playwright .stop = self .__aexit__ # type: ignore
118
+ return playwright
119
+
120
+ async def start (self ) -> AsyncPlaywright :
121
+ return await self .__aenter__ ()
112
122
113
- async def __aexit__ (self , exc_type : Any , exc_val : Any , exc_tb : Any ) -> None :
123
+ async def __aexit__ (self , * args : Any ) -> None :
114
124
self ._connection .stop_async ()
115
125
116
126
0 commit comments