Skip to content

Commit b2a7265

Browse files
committed
Allow Chrome to load speech worker from CDN in a page from a file:// URL
1 parent 4d1e195 commit b2a7265

5 files changed

Lines changed: 9 additions & 12 deletions

File tree

components/mjs/a11y/speech/speech.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if (MathJax.loader) {
1414
} else {
1515
const REQUIRE = typeof require !== 'undefined' ? require : MathJax.config.loader.require;
1616
if (REQUIRE?.resolve) {
17-
path = REQUIRE.resolve(`${path}/package.json`).replace(/\/[^\/]*$/, '');
17+
path = REQUIRE.resolve(`${path}/require.mjs`).replace(/\/[^\/]*$/, '');
1818
maps = REQUIRE.resolve(`${maps}/base.json`).replace(/\/[^\/]*$/, '');
1919
} else {
2020
path = maps = '';

components/mjs/a11y/sre/worker/config.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"to": "../../../../../bundle/sre",
77
"from": "../../../../../ts/a11y/sre",
88
"copy": [
9-
"package.json",
109
"require.mjs",
1110
"require.d.mts"
1211
]

ts/a11y/sre/package.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

ts/a11y/sre/speech-worker.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,12 @@ declare const SRE: any;
110110
//
111111
// Load SRE
112112
//
113-
await import('./sre.js')
114-
.catch((_) => import(/* webpackIgnore: true */ './sre-lab.js')) // for use in the lab
115-
.then((SRE) => {
116-
global.SRE = SRE;
117-
});
113+
await (
114+
global.isLab
115+
? import(/* webpackIgnore: true */ './sre-lab.js') // for use in the lab
116+
: import('./sre.js')
117+
)
118+
.then((SRE) => (global.SRE = SRE));
118119

119120
/*****************************************************************/
120121

ts/adaptors/HTMLAdaptor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,12 +627,12 @@ export class HTMLAdaptor<
627627
const file = `${path}/${worker}`;
628628
const content = `
629629
self.maps = '${quoted(maps)}';
630-
import('${quoted(file)}');
630+
importScripts('${quoted(file)}');
631631
`;
632632
const url = URL.createObjectURL(
633633
new Blob([content], { type: 'text/javascript' })
634634
);
635-
const webworker = new Worker(url, { type: 'module' });
635+
const webworker = new Worker(url);
636636
webworker.onmessage = listener;
637637
URL.revokeObjectURL(url);
638638
return webworker;

0 commit comments

Comments
 (0)