Silence rejected promise from beforeunload RuntimeMessage - sendMessage

Viewed 165

Having an extension where I add a listener to beforeunload to a popup opened by BrowserAction.

When popup is closed I send a message to background script with window size and position. The background script, in turn, saves this to browser storage.

browser.runtime.sendMessage({
    action: 'save_state',
    data: {
        width   : window.outerWidth,
        height  : window.outerHeight,
        top     : window.screenTop,
        left    : window.screenLeft
    }
});

Issue is that the popup is closed before the message is resolved resulting in:

Promise rejected after context unloaded: Actor 'Conduits' destroyed before query 'RuntimeMessage' was resolved

It usually is saved, and if not, there is not much I can do about it. Issue is that it almost always result in mentioned error. It is ugly and I would like to silence it or demote it to debug from error in logs.

  1. Is there a better way to do this?
  2. If not is there a way to silence it?

Have tried with

browser.runtime.sendMessage(...).catch(e => {});

// --

try {
    browser.runtime.sendMessage(...).catch(e => {});
} catch (e) { }

etc.

Have also tried to save directly from the popup, but this is more fragile and fails more often.

0 Answers
Related