Skip to content

Allow Chrome to load speech worker from CDN in a page from a file:// URL #1290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

dpvc
Copy link
Member

@dpvc dpvc commented Jul 2, 2025

This PR fixes a problem with importing the worker code from a page the was loaded from a file:// URL with Mathjax coming from the CDN. The problem only seems to affect Chrome, which won't allow the cross-origin load, even though the CDN marks the script as allowed.

The solution is to use importScripts() rather than import() to get the worker code. That means the worker can't be loaded as a module, as importScripts() isn't allowed there.

The package.json file is no longer needed, and the worker doesn't need to be a module anymore (that could have been removed when the worker-pool was removed, as that was only needed for the iframe hack to the liteDOM).

The v4-lab needs a new way to detect the need for the sre-lab.js file, as the importScripts() can't load an ES6 module, and the compiled speech-worker.js is such a module. So we need to use import() in the lab. The ww-v4-lab branch in the MathJax-dev repository has the needed changes: the HTML adaptor is subclasses and the createWorker() method is overridden with one that uses import(), and also sets self.isLab = true to mark the fact that the worker is running int he lab. The worker now uses that value to determine whether to load sre-lab.js or sre.js, so that is a bit cleaner than having to test for the failure of SRE loading.

@dpvc dpvc requested a review from zorkow July 2, 2025 14:31
@dpvc dpvc added this to the v4.0 milestone Jul 2, 2025
Copy link

codecov bot commented Jul 2, 2025

Codecov Report

Attention: Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Project coverage is 86.71%. Comparing base (4d1e195) to head (e6b134d).

Files with missing lines Patch % Lines
ts/adaptors/HTMLAdaptor.ts 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           develop    #1290     +/-   ##
==========================================
  Coverage    86.71%   86.71%             
==========================================
  Files          337      337             
  Lines        83979    83979             
  Branches      4750     3124   -1626     
==========================================
  Hits         72826    72826             
- Misses       11130    11153     +23     
+ Partials        23        0     -23     

☔ View full report in Codecov by Sentry.
📢 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.

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