Repository navigation
Conversation
A callback that throws is reported by dispatching a plain Event of type "error" on the global. A plain Event does not get the special handling an ErrorEvent gets on the global, so self.onerror is called with the event object as its only argument: no message, no source, and no exception.
When a queued callback threw, the polyfill reported it by dispatching a plain Event of type "error" on the global, with message, filename, lineno and error set as expando properties. Only an ErrorEvent gets the special handling on the global that calls onerror with (message, source, lineno, colno, error), so onerror received the bare event and handlers that read the exception from the fifth argument never saw it. A thrown value that is not an object (`throw null`) also made the handler itself throw while reading `e.message`. The exception is now reported with an ErrorEvent, as the code's own TODO intended, so both onerror and error listeners receive the message and the exception, as they do for an exception reported by the browser. Where ErrorEvent cannot be constructed (IE), the previous Event with expando properties remains the fallback. queueMicrotask is served to Chrome < 71, Firefox < 69, Safari < 12.1, iOS Safari < 12.2, Opera < 58, Samsung Internet < 10, IE and legacy Edge.
…runs A browser reports an exception from a microtask as soon as that microtask ends, before the next one runs. The polyfill reports it from a catch handler chained after the callback, a microtask or more later, so with callbacks A, B (throws) and C the error event fires after C has already run.
The callback ran in a promise reaction and its exception was caught and re-dispatched as a synthetic ErrorEvent from a catch handler chained after it. That event arrived a microtask or more late, after later callbacks had run; it was untrusted; and the browser never logged the exception as uncaught, because it had been caught. Each callback now runs inside the dispatch of a synthetic event on a private element. An exception thrown by an event listener is reported by the browser itself, synchronously, exactly as an uncaught error: onerror gets the browser's message, source, line, column and the error object, error listeners get a trusted ErrorEvent, the console logs it as uncaught, and dispatchEvent still returns, so the next callback runs after the report. Without a document (workers), the exception is rethrown from a timer instead. The ErrorEvent construction, its IE fallback and the Event dependency are gone, and the onerror test no longer needs the ErrorEvent constructor. queueMicrotask is served to Chrome < 71, Firefox < 69, Safari < 12.1, iOS Safari < 12.2, Opera < 58, Samsung Internet < 10, IE and legacy Edge.
puckey
added a commit
to puckey/polyfill-service
that referenced
this pull request
Oct 2, 2026
The callback ran in a promise reaction and its exception was caught and re-dispatched as a synthetic error Event from a catch handler chained after it. That event arrived a microtask or more late, after later callbacks had run; it was a plain Event, so onerror received the event instead of the message, source, line, column and error; and the browser never logged the exception as uncaught, because it had been caught. Each callback now runs inside the dispatch of a synthetic event on a private element. The browser reports an exception thrown by an event listener itself, synchronously, as an uncaught error: onerror and error listeners get the error object, the console logs it, and dispatchEvent still returns, so the next callback runs after the report. Without a document the exception is rethrown from a timer. This is the fix from radio-garden/polyfill-library#8. The polyfill no longer constructs an Event, so meta.json drops the Event dependency, as the fork's config.toml does; the service uses meta.json dependencies to pull features into a targeted bundle and to order it. `test/unit/queuemicrotask-error.test.ts` passes for raw.js and min.js. min.js is re-minified with terser (--compress --mangle --ie8 --safari10 --ecma 5) and the size in meta.json follows. No golden moves: the configured features (default, fetch) do not include queueMicrotask.
bigmistqke
pushed a commit
to puckey/polyfill-service
that referenced
this pull request
Oct 5, 2026
The callback ran in a promise reaction and its exception was caught and re-dispatched as a synthetic error Event from a catch handler chained after it. That event arrived a microtask or more late, after later callbacks had run; it was a plain Event, so onerror received the event instead of the message, source, line, column and error; and the browser never logged the exception as uncaught, because it had been caught. Each callback now runs inside the dispatch of a synthetic event on a private element. The browser reports an exception thrown by an event listener itself, synchronously, as an uncaught error: onerror and error listeners get the error object, the console logs it, and dispatchEvent still returns, so the next callback runs after the report. Without a document the exception is rethrown from a timer. This is the fix from radio-garden/polyfill-library#8. The polyfill no longer constructs an Event, so meta.json drops the Event dependency, as the fork's config.toml does; the service uses meta.json dependencies to pull features into a targeted bundle and to order it. `test/unit/queuemicrotask-error.test.ts` passes for raw.js and min.js. min.js is re-minified with terser (--compress --mangle --ie8 --safari10 --ecma 5) and the size in meta.json follows. No golden moves: the configured features (default, fetch) do not include queueMicrotask.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
written by claude
When a queued callback threw, the polyfill reported it by dispatching a
plain Event of type "error" on the global, with message, filename,
lineno and error set as expando properties. Only an ErrorEvent gets the
special handling on the global that calls onerror with (message,
source, lineno, colno, error), so onerror received the bare event and
handlers that read the exception from the fifth argument never saw it.
A thrown value that is not an object (
throw null) also made thehandler itself throw while reading
e.message.The exception is now reported with an ErrorEvent, as the code's own
TODO intended, so both onerror and error listeners receive the message
and the exception, as they do for an exception reported by the
browser. Where ErrorEvent cannot be constructed (IE), the previous Event
with expando properties remains the fallback.
queueMicrotask is served to Chrome < 71, Firefox < 69, Safari < 12.1,
iOS Safari < 12.2, Opera < 58, Samsung Internet < 10, IE and legacy
Edge.
Testing
Each fix commit follows a commit that adds failing cases to the polyfill's
polyfill.test.js. The cases were run in jsdom with the polyfill forced to install: they fail before the fix and pass after. They have not yet run in a real browser.