@@ -68,9 +68,10 @@ async def send_return_as_dict(self, method: str, params: Dict = None) -> Any:
6868 )
6969
7070 def send_no_reply (self , method : str , params : Dict = None ) -> None :
71+ # No reply messages are used to e.g. waitForEventInfo(after).
7172 self ._connection .wrap_api_call_sync (
7273 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
7475 )
7576 )
7677
@@ -178,6 +179,7 @@ def remove_listener(self, event: str, f: Any) -> None:
178179class ProtocolCallback :
179180 def __init__ (self , loop : asyncio .AbstractEventLoop ) -> None :
180181 self .stack_trace : traceback .StackSummary
182+ self .no_reply : bool
181183 self .future = loop .create_future ()
182184 # The outer task can get cancelled by the user, this forwards the cancellation to the inner task.
183185 current_task = asyncio .current_task ()
@@ -305,7 +307,7 @@ def set_in_tracing(self, is_tracing: bool) -> None:
305307 self ._tracing_count -= 1
306308
307309 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
309311 ) -> ProtocolCallback :
310312 if self ._closed_error_message :
311313 raise Error (self ._closed_error_message )
@@ -317,6 +319,7 @@ def _send_message_to_server(
317319 traceback .StackSummary ,
318320 getattr (task , "__pw_stack_trace__" , traceback .extract_stack ()),
319321 )
322+ callback .no_reply = no_reply
320323 self ._callbacks [id ] = callback
321324 stack_trace_information = cast (ParsedStackTrace , self ._api_zone .get ())
322325 frames = stack_trace_information .get ("frames" , [])
@@ -357,6 +360,10 @@ def dispatch(self, msg: ParsedMessagePayload) -> None:
357360 callback = self ._callbacks .pop (id )
358361 if callback .future .cancelled ():
359362 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
360367 error = msg .get ("error" )
361368 if error :
362369 parsed_error = parse_error (error ["error" ]) # type: ignore
0 commit comments