Catching specific error from browser API

I need to handle browser specific error "Message manager disconnected". The error seems to be general type “Error” so the only way (I can think of) to distinguish it is to check if:

if (err.message === 'Message manager disconnected')

But is this a good idea? Is it likely that the error message would change in the future or that it’s different on different build (translated maybe?).

Maybe there is something in err.stack that can help? In any case, I guess it’s never going to be guaranteed to be a stable test forever but at least with a stack frame it’s definitely not going to vary across translated locales (although the error message probably won’t be either).

The “stack” doesn’t help much, it’s just two lines (one empty and one where my code calls browser.tabs.sendMessage):

09:55:37.583 err.stack
09:55:37.640 "sendTabMessage@moz-extension://57fd0f4b-24a5-46d9-9415-1d38a5d123c8/background/background_gsd.js:3766:70

But the good news is that the error is actually fixed in Firefox 79! Hoorey!
Too bad it missed ESR 78 though :frowning: