When an extension is reloaded or removed, certain Chrome APIs in its content scripts switch to throwing "Extension context invalidated" errors when called. The InboxSDK is mostly unaffected since it mostly doesn't use these APIs, except when logging an error it tries to get the extension's ID using a Chrome API. This means that the next time the InboxSDK tries to log an error after the extension is reloaded or removed, the InboxSDK ends up interrupting itself with a new error from trying to look up the extension ID. (This doesn't cause an infinite loop because we catch any errors thrown while logging an error and log them through a simpler code path, but it does add a lot of noise in the console that distracts from any actual errors triggered by the extension itself.)
This PR fixes this by:
The getExtensionId() function now uses a try-catch and logs any errors itself instead of letting the error be thrown from it, since for all of the uses of the function it's better to have a null instead of being interrupted by an error.
We call getExtensionId() once on startup and cache its result, so that way if it's called again later after the extension has been reloaded or removed, it still remembers the extension's ID.
When an extension is reloaded or removed, certain Chrome APIs in its content scripts switch to throwing "Extension context invalidated" errors when called. The InboxSDK is mostly unaffected since it mostly doesn't use these APIs, except when logging an error it tries to get the extension's ID using a Chrome API. This means that the next time the InboxSDK tries to log an error after the extension is reloaded or removed, the InboxSDK ends up interrupting itself with a new error from trying to look up the extension ID. (This doesn't cause an infinite loop because we catch any errors thrown while logging an error and log them through a simpler code path, but it does add a lot of noise in the console that distracts from any actual errors triggered by the extension itself.)
This PR fixes this by:
null
instead of being interrupted by an error.