Closed Bug 1799406 Opened 2 years ago Closed 2 years ago

Errors thrown by the extension inside an API event listener do not show up in the console

Categories

(DevTools :: Console, defect)

Firefox 106
defect

Tracking

(Not tracked)

RESOLVED DUPLICATE of bug 1792559

People

(Reporter: mckravchyk, Unassigned)

Details

Attachments

(1 file)

Steps to reproduce:

Try running the following code in either a sidebar frame or a background page:

window.onerror = (
  event,
  source,
  lineno,
  colno,
  error,
) => {
  console.error(error);
};

(function() {
  window.browser.tabs.onCreated.addListener(() => {
    console.log('throwing in the event listener...');
    // It's not thrown. It's not even visible with window.onError and window.onUnhandledPromiseRejection
    throw new Error('thrown in the event listener');
    // The error never makes it to the console, but the code execution stops. The error can also
    // be caught
    console.log('after throw');
  });

  throw new Error('thrown in the top scope'); // ok

  // Errors thrown in promises and DOM event listeners are visible
}());

Actual results:

Notice that when you create a new tab, only the console.log prior to the error thrown is visible in the console. The error does not show up in the console, despite occurring and stopping further code execution (it can be caught too). The error does not even show in window.onerror callback.

There's no way to detect an error and it makes debugging much harder, i.e. I have spent an hour investigating something that would normally immediately show up as an error :(

Expected results:

Any error thrown should appear in the console

I have found similar issues but they are from a decade ago.

Reproduced in 106.0.5 and 107.0.b9 (Linux)

The Bugbug bot thinks this bug should belong to the 'DevTools::Console' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → Console
Product: Firefox → DevTools

Hello Maciej,

Can you see those in the webextension toolbox (using about:debugging#/runtime/this-firefox and inspecting the extension that is throwing)

Flags: needinfo?(mckravchyk)

Hello Nicolas,

no, no errors are showing there.

Flags: needinfo?(mckravchyk)

Nicolas, can you try to reproduce?

Flags: needinfo?(nchevobbe)
Attached file ff-api-bug.zip

I'm attaching a sample extension that is affected by this problem. It loads panel.js script in both the Sidebar and as a background script.

Steps to reproduce:

  1. Load the extension
  2. Open the console for any context
  3. Create a new tab
  4. Notice "Throwing in the event listener..." x2
  5. Notice that no error has been caught anywhere, even with window.onerror and that the execution is stopped, indicating that the error was thrown

(In reply to Julian Descottes [:jdescottes] from comment #4)

Nicolas, can you try to reproduce?

Sorry about the lag. Yes I can reproduce.
We're hitting https://searchfox.org/mozilla-central/rev/df68a65540f2227e27a12ed0b491188e2927f6d5/devtools/server/actors/resources/error-messages.js#81-83

if (!message.innerWindowID) {
  return false;
}

as message.innerWindowID is 0.
Alex, does that look similar to the work you did recently around webextension logs ? I seem to recall you did something to put the right innerWindowID on some messages ?

Flags: needinfo?(nchevobbe) → needinfo?(poirot.alex)

I think it will be fixed by bug 1792559.

Luca, could you confirm?

Flags: needinfo?(poirot.alex) → needinfo?(lgreco)

(In reply to Alexandre Poirot [:ochameau] from comment #7)

I think it will be fixed by bug 1792559.

Luca, could you confirm?

yes it is, they are technically duplicate of each other, investigating Bug 1792559 have confirmed that the issue is the same for any WebExtensions API events not just webRequest.

Would you be ok from your perspective if we close this as a duplicate of Bug 1792559 (and tweak Bug 1792559 summary to make it clear is not specific to webRequest listeners)?

Flags: needinfo?(lgreco)

Sure, your are on it, do whatever makes sense in term of bugzilla dependencies.

Status: UNCONFIRMED → RESOLVED
Closed: 2 years ago
Duplicate of bug: 1792559
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: