Native-messaging API--catching a connection request failure versus a genuine disconnection

Thanks. I’m not trying to complain about it, if it comes across like that.

Regardless of whether or not the request for a port was successful, nativeApp.port.error is null immediately after the request. The onDisconnect event does fire and at that stage the value is No such native application NatAppName.

nativeApp.port = browser.runtime.connectNative( "NatAppName" );
console.log( nativeApp.port );
// This won't work.
if ( nativeApp.port.error )
    {
      console.log( "Error connecting to nativeApp." );
      return;
    }
else
    console.log( "Communication port established." );

nativeApp.port.onDisconnect.addListener( ( p ) =>
   {
     console.log( p );
      if ( p.error )
         console.log( `Disconnected due to an error: ${ p.error.message }` );
   } );

It’s like browser.runtime.connectNative() is an asynchronous request that only tells you when it fails and not when it succeeded?

I don’t know how else it could be done, except perhaps like an indexedDB request has the result property in the successful request object, such that the port could be assigned after the connection is known to be successful.

It works as it is; I just wanted to make sure I wasn’t missing something. Thanks again.