Skip to content

Commit 30bd639

Browse files
authored
Merge pull request #1290 from mathjax/fix/file-url-worker
Allow Chrome to load speech worker from CDN in a page from a file:// URL
2 parents cde957c + e6b134d commit 30bd639

6 files changed

Lines changed: 8 additions & 14 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
]

components/mjs/a11y/sre/worker/webpack.cjs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
const webpack = require('webpack');
22

33
module.exports = (pkg) => {
4-
pkg.experiments = {outputModule: true};
5-
pkg.output.library = {type: 'module'};
64
pkg.plugins.push(
75
new webpack.optimize.LimitChunkCountPlugin({
86
maxChunks: 1,

ts/a11y/sre/package.json

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

ts/a11y/sre/speech-worker.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ 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+
).then((SRE) => (global.SRE = SRE));
118118

119119
/*****************************************************************/
120120

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)