Main world injection: Don't serialize results/errors #1534
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
As noted in #1466 (comment), Firefox—for whatever reason—gives a useless "uncaught exception: Object" message if you throw an object in an async function, and we currently throw objects out of injected functions due to the need to serialize them to JSON.
Fun fact, however: we don't need to serialize them to JSON.
CustomEvent
s support sending anyStructuredClone
-able value in Chromium, and Firefox... *mumble mumble xray vision mumble*.This PR therefore removes the serialization step entirely, resulting in a native Error object being used here (still no stack, like Chromium has, but, progress):
Oddly, I'm not observing the
cloneInto()
call I needed to make this work in Firefox in1052f23
(#1284) being necessary, when testing this current code in Firefox 126. I don't know whether this is due to MV3, due to a change in Firefox, or both. Therefore, big caveat: merging this PR without would require us to confirm thatcloneInto()
is not required in any Firefox version we support.Not well-tested at time of writing. I would like to see if this works on
Response
objects.Testing steps