Skip to content

Commit

Permalink
Fix feature detection for Pyodide 0.26.0
Browse files Browse the repository at this point in the history
We want Pyodide to decide we're a browser. It checks a few extra things in
0.26.0 before being convinced of this.
  • Loading branch information
hoodmane committed Sep 4, 2024
1 parent 485a7ba commit d76bc78
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/pyodide/internal/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,16 @@ async function instantiateEmscriptenModule(
// They used to have an `environment` setting that did this but it has been
// removed =(
// If/when we link our own Pyodide we can remove this.
// @ts-ignore
globalThis.window = {}; // makes ENVIRONMENT_IS_WEB = true
// @ts-ignore
globalThis.importScripts = 1; // makes ENVIRONMENT_IS_WORKER = false
const global = globalThis as any;
global.window = {}; // makes ENVIRONMENT_IS_WEB = true
global.document = { createElement() {} };
global.sessionStorage = {};
global.importScripts = 1; // makes ENVIRONMENT_IS_WORKER = false
const p = _createPyodideModule(emscriptenSettings);
// @ts-ignore
delete globalThis.window;
// @ts-ignore
delete globalThis.importScripts;
delete global.window;
delete global.document;
delete global.sessionStorage;
delete global.importScripts;
const emscriptenModule = await p;
return emscriptenModule;
} catch (e) {
Expand Down

0 comments on commit d76bc78

Please sign in to comment.