@@ -40,6 +40,7 @@ const devtoolsMachine = interpret(
4040
4141let panelHidden = true ;
4242let connectTimeoutId : NodeJS . Timeout ;
43+ let disconnectTimeoutId : NodeJS . Timeout ;
4344
4445const port = browser . runtime . connect ( {
4546 name : inspectedTabId . toString ( ) ,
@@ -50,6 +51,12 @@ const rpcClient = createRpcClient<DevtoolsRPCMessage>(
5051 createPortMessageAdapter ( port )
5152) ;
5253
54+ devtoolsMachine . subscribe ( ( { value } ) => {
55+ if ( value === "connected" ) {
56+ clearTimeout ( disconnectTimeoutId ) ;
57+ }
58+ } ) ;
59+
5360// In case we can't connect to the tab, we should at least show something to the
5461// user when we've attempted to connect a max number of times.
5562function startConnectTimeout ( attempts = 0 ) {
@@ -73,12 +80,17 @@ clientPort.on("connectToDevtools", (message) => {
7380 } ) ;
7481} ) ;
7582
76- clientPort . on ( "connectToClientTimeout " , ( ) => {
77- devtoolsMachine . send ( "timeout" ) ;
83+ clientPort . on ( "registerClient " , ( message ) => {
84+ devtoolsMachine . send ( { type : "connect" , clientContext : message . payload } ) ;
7885} ) ;
7986
8087clientPort . on ( "disconnectFromDevtools" , ( ) => {
88+ clearTimeout ( disconnectTimeoutId ) ;
8189 devtoolsMachine . send ( "disconnect" ) ;
90+
91+ disconnectTimeoutId = setTimeout ( ( ) => {
92+ devtoolsMachine . send ( "clientNotFound" ) ;
93+ } , 10_000 ) ;
8294} ) ;
8395
8496clientPort . on ( "clientNotFound" , ( ) => {
0 commit comments