From d76bc780e1cc8dd29df3f574938128139ec5bf4f Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Wed, 4 Sep 2024 11:13:25 +0200 Subject: [PATCH] Fix feature detection for Pyodide 0.26.0 We want Pyodide to decide we're a browser. It checks a few extra things in 0.26.0 before being convinced of this. --- src/pyodide/internal/python.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/pyodide/internal/python.ts b/src/pyodide/internal/python.ts index 81050365188..37d1372600c 100644 --- a/src/pyodide/internal/python.ts +++ b/src/pyodide/internal/python.ts @@ -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) {