Skip to content

Better handling of errors when starting up the speech worker. (mathjax/MathJax#3620) - #1583

Open
dpvc wants to merge 1 commit into
developfrom
issue3620
Open

dpvc wants to merge 1 commit into
developfrom
issue3620

Conversation

@dpvc

@dpvc dpvc commented Oct 24, 2026

Copy link
Copy Markdown
Member

This PR adds more support for handling errors when starting up the SRE webworker. It turns out that in some settings (due to security settings) WebKit fails to load the webworker in a way that isn't currently being caught, leading to the startup promise not being settled. In addition, new promise-based requests to typeset additional material on the page also fail to resolve.

We address both these issues here. In a11y/speech/WebWorker.ts, we add an onerror handler to the webworker that detects the failure to start up, and call the Failed() command in that case, which triggers the worker to be shut down and any pending tasks to be rejected. (This resolves the first issue above.) We add a new stopped property that indicates that the worker has been stopped, so that no new tasks are rejected immediately by the Post() command. (This resolves the second issue above.)

It turns out that the calls to the Failed() command were not passing a proper Message object but rather a string, so that has been fixed by using {error: message} rather than just message as its argument. (Typescript didn't catch this because of the indirection involved in calling the function.) This required changes in the DOM adaptors.

In addition, the onerror handler needed to be added to the minWorker interface, so we could use it in WebWorker.ts, and so we needed to add it to the LiteWorker in the NodeMixin.ts file.

Finally, the source of the problem in WebKit is that the blob URL created for the webworker bootstrap code doesn't work in an origin-less setting (like the one described in mathjax/MathJax#3620), but a data: URL would work. So HTMLAdaptor.ts checks for window.origin === 'null' and uses a data: url in that case rather than the blob. This makes the code in the initial issue report run properly in Safari as well.

Resolves issue mathjax/MathJax#3620.

@dpvc
dpvc requested a review from zorkow October 24, 2026 19:31
@dpvc dpvc added this to the v4.2 milestone Oct 24, 2026
@codecov

codecov Bot commented Oct 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 12.50000% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.13%. Comparing base (40a284d) to head (a917869).

Files with missing lines Patch % Lines
ts/adaptors/HTMLAdaptor.ts 0.00% 5 Missing ⚠️
ts/adaptors/NodeMixin.ts 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1583      +/-   ##
===========================================
- Coverage    87.13%   87.13%   -0.01%     
===========================================
  Files          392      392              
  Lines        89280    89283       +3     
  Branches      5080     5080              
===========================================
+ Hits         77794    77795       +1     
+ Misses       11486    11467      -19     
- Partials         0       21      +21     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant