Open Bug 1943721 Opened 20 days ago Updated 17 days ago

Errors thrown in a sync message event handler are not logged in the throwing context's console

Categories

(WebExtensions :: Developer Tools, defect, P3)

Firefox 134
defect

Tracking

(Not tracked)

People

(Reporter: dotproto, Unassigned)

References

(Depends on 1 open bug)

Details

Attachments

(1 file)

Attached file bug-repro.zip

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:136.0) Gecko/20100101 Firefox/136.0

While testing inter-extension message passing, I observed that a bug created by a typo in my browser.runtime.onMessageExternal event listener appeared in the console of the context that sent the original message and DID NOT appear in the console of the context where the error was actually thrown. This made it difficult to trace where the error came from.

Steps to reproduce

1: Unzip the attached bug-repro.zip file and install the "alice" and "bob" sub-directories as temporary extensions.
2. Open a developer tool session for both alice@test and bob@test and position the windows so you can see the logs of both simultaneously.
3. Run the following command in bob@test's console: send.error()

Observed result

The error generated in bob@test is not logged in bob@test's console. alice@test receives a sanitized version of the thrown error – the cause property is removed and the stack property is regenerated for the site of the runtime.sendMessage call.

In the console logs that follow, lines that begin with > indicate commands executed by the user and lines that begin with < indicate messages logged to the console.

Alice's console

> send.error()
< Promise { <state>: "pending" }
< 
< [alice@test catch] Sent "error", response Error: Generated in bob@test
<     _base moz-extension://3bb7617a-24fe-444b-9216-8597a23b015d/alice-bg.js:44
<     error moz-extension://3bb7617a-24fe-444b-9216-8597a23b015d/alice-bg.js:58
<     <anonymous> debugger eval code:1
​```

### Bob's console

< [bob@test] msg from alice@test Object { type: "error" }
< NOTE: This error is NOT logged in bob@test's background script.


## Expected result

The error thrown on line 19 of bob-bg.js should be logged to the `bob@test` console.  

## Additional details

Asynchronously generated errors in the recipient's event handler behave as expected; the error logged in bob@test's console and contains the `cause` and `stack` values appropriate for this context. To see this in action, execute `send.errorAsync()` in alice@test's console.

Also, I'm not sure that automatically passing a sanitized error back to the call `runtime.sendMessage()` call site is appropriate. The `sendMessage` operation triggered in alice@test completed as expected. If an error occurred in bob@test's event handler, it is bob@test's responsibility to communicate that back to the sender appropriately. This would also bring the behavior more in line with developer expectations from working with web's messaging APIs, which don't have an implicit return value.

This is probably a duplicate of bug 1940287; I'm marking this as "depends on" rather than a duplicate so you can more easily track the changes of the other bug and mark this bug as fixed/duplicate when the patch to the other bug lands.

Severity: -- → S4
Depends on: 1940287
Priority: -- → P3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: