@@ -207,20 +207,19 @@ export class PyScriptApp {
207
207
208
208
this . logStatus ( `Downloading ${ interpreter_cfg . name } ...` ) ;
209
209
210
- // download pyodide by using a <script> tag. Once it's ready, the
211
- // "load" event will be fired and the execution logic will continue.
212
- // Note that the load event is fired asynchronously and thus any
213
- // exception which is throw inside the event handler is *NOT* caught
214
- // by the try/catch inside main(): that's why we need to .catch() it
215
- // explicitly and call _handleUserErrorMaybe also there.
216
- const script = document . createElement ( 'script' ) ; // create a script DOM node
217
- script . src = await this . interpreter . _remote . src ;
218
- script . addEventListener ( 'load' , ( ) => {
219
- this . afterInterpreterLoad ( this . interpreter ) . catch ( async error => {
220
- await this . _handleUserErrorMaybe ( error ) ;
221
- } ) ;
222
- } ) ;
223
- document . head . appendChild ( script ) ;
210
+ /* Dynamically download and import pyodide: the import() puts a
211
+ loadPyodide() function into globalThis, which is later called by
212
+ RemoteInterpreter.
213
+
214
+ This is suboptimal: ideally, we would like to import() a module
215
+ which exports loadPyodide(), but this plays badly with workers
216
+ because at the moment of writing (2023-03-24) Firefox does not
217
+ support ES modules in workers:
218
+ https://caniuse.com/mdn-api_worker_worker_ecmascript_modules
219
+ */
220
+ const interpreterURL = await this . interpreter . _remote . src ;
221
+ await import ( interpreterURL ) ;
222
+ await this . afterInterpreterLoad ( this . interpreter ) ;
224
223
}
225
224
226
225
// lifecycle (5)
0 commit comments