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

Merged
merged 3 commits into from
Jul 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/mjs/a11y/speech/speech.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if (MathJax.loader) {
} else {
const REQUIRE = typeof require !== 'undefined' ? require : MathJax.config.loader.require;
if (REQUIRE?.resolve) {
path = REQUIRE.resolve(`${path}/package.json`).replace(/\/[^\/]*$/, '');
path = REQUIRE.resolve(`${path}/require.mjs`).replace(/\/[^\/]*$/, '');
maps = REQUIRE.resolve(`${maps}/base.json`).replace(/\/[^\/]*$/, '');
} else {
path = maps = '';
Expand Down
1 change: 0 additions & 1 deletion components/mjs/a11y/sre/worker/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"to": "../../../../../bundle/sre",
"from": "../../../../../ts/a11y/sre",
"copy": [
"package.json",
"require.mjs",
"require.d.mts"
]
Expand Down
2 changes: 0 additions & 2 deletions components/mjs/a11y/sre/worker/webpack.cjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const webpack = require('webpack');

module.exports = (pkg) => {
pkg.experiments = {outputModule: true};
pkg.output.library = {type: 'module'};
pkg.plugins.push(
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1,
Expand Down
3 changes: 0 additions & 3 deletions ts/a11y/sre/package.json

This file was deleted.

10 changes: 5 additions & 5 deletions ts/a11y/sre/speech-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ declare const SRE: any;
//
// Load SRE
//
await import('./sre.js')
.catch((_) => import(/* webpackIgnore: true */ './sre-lab.js')) // for use in the lab
.then((SRE) => {
global.SRE = SRE;
});
await (
global.isLab
? import(/* webpackIgnore: true */ './sre-lab.js') // for use in the lab
: import('./sre.js')
).then((SRE) => (global.SRE = SRE));

/*****************************************************************/

Expand Down
4 changes: 2 additions & 2 deletions ts/adaptors/HTMLAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,12 +627,12 @@
const file = `${path}/${worker}`;
const content = `
self.maps = '${quoted(maps)}';
import('${quoted(file)}');
importScripts('${quoted(file)}');

Check warning on line 630 in ts/adaptors/HTMLAdaptor.ts

View check run for this annotation

Codecov / codecov/patch

ts/adaptors/HTMLAdaptor.ts#L630

Added line #L630 was not covered by tests
`;
const url = URL.createObjectURL(
new Blob([content], { type: 'text/javascript' })
);
const webworker = new Worker(url, { type: 'module' });
const webworker = new Worker(url);

Check warning on line 635 in ts/adaptors/HTMLAdaptor.ts

View check run for this annotation

Codecov / codecov/patch

ts/adaptors/HTMLAdaptor.ts#L635

Added line #L635 was not covered by tests
webworker.onmessage = listener;
URL.revokeObjectURL(url);
return webworker;
Expand Down