@@ -68,9 +68,10 @@ async def send_return_as_dict(self, method: str, params: Dict = None) -> Any:
68
68
)
69
69
70
70
def send_no_reply (self , method : str , params : Dict = None ) -> None :
71
+ # No reply messages are used to e.g. waitForEventInfo(after).
71
72
self ._connection .wrap_api_call_sync (
72
73
lambda : self ._connection ._send_message_to_server (
73
- self ._guid , method , {} if params is None else params
74
+ self ._guid , method , {} if params is None else params , True
74
75
)
75
76
)
76
77
@@ -178,6 +179,7 @@ def remove_listener(self, event: str, f: Any) -> None:
178
179
class ProtocolCallback :
179
180
def __init__ (self , loop : asyncio .AbstractEventLoop ) -> None :
180
181
self .stack_trace : traceback .StackSummary
182
+ self .no_reply : bool
181
183
self .future = loop .create_future ()
182
184
# The outer task can get cancelled by the user, this forwards the cancellation to the inner task.
183
185
current_task = asyncio .current_task ()
@@ -305,7 +307,7 @@ def set_in_tracing(self, is_tracing: bool) -> None:
305
307
self ._tracing_count -= 1
306
308
307
309
def _send_message_to_server (
308
- self , guid : str , method : str , params : Dict
310
+ self , guid : str , method : str , params : Dict , no_reply : bool = False
309
311
) -> ProtocolCallback :
310
312
if self ._closed_error_message :
311
313
raise Error (self ._closed_error_message )
@@ -317,6 +319,7 @@ def _send_message_to_server(
317
319
traceback .StackSummary ,
318
320
getattr (task , "__pw_stack_trace__" , traceback .extract_stack ()),
319
321
)
322
+ callback .no_reply = no_reply
320
323
self ._callbacks [id ] = callback
321
324
stack_trace_information = cast (ParsedStackTrace , self ._api_zone .get ())
322
325
frames = stack_trace_information .get ("frames" , [])
@@ -357,6 +360,10 @@ def dispatch(self, msg: ParsedMessagePayload) -> None:
357
360
callback = self ._callbacks .pop (id )
358
361
if callback .future .cancelled ():
359
362
return
363
+ # No reply messages are used to e.g. waitForEventInfo(after) which returns exceptions on page close.
364
+ # To prevent 'Future exception was never retrieved' we just ignore such messages.
365
+ if callback .no_reply :
366
+ return
360
367
error = msg .get ("error" )
361
368
if error :
362
369
parsed_error = parse_error (error ["error" ]) # type: ignore
0 commit comments