Automatically patch js.document
and js.window
in Workers
#1878
Closed
WebReflection
started this conversation in
Proposals
Replies: 1 comment 16 replies
-
This is a great topic. Thanks @WebReflection for kicking it off. Agree with you that we have a little bit of a dilemma having to choose transparency versus compatibility/usability. All In all, I think we should lean towards making the user experience as pleasant as possible while at the same time leaving an escape hatch. How about we keep the patches as a default behavior and offer a config option to turn it off? This way the default will probably match what most users would need but we still have an option for people to explicitly turn it off and use Pyodide's own interface. |
Beta Was this translation helpful? Give feedback.
16 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Not only some Pyodide module assumes by default that code runs on the main thread, hence it reaches
js.document
without thinking that could be absent, we once again had some user finding the lack ofdocument
problematic.I remember me and @fpliger also needed to manually patch that and point at the proxied version and I start wondering, as we already offer a
RUNNING_IN_WORKER
constant viapyscript
module, if we shouldn't just stretch further and enable more modules and reduce surprises when a scriptworker
attribute is used.That means that beside reaching out for
pyscript.window
andpyscript.document
, the global Worker context gets polluted with both references pointing at our module.This makes the code easier to migrate but I am not sure this might create confusion, as w estill want people to understand that
pyscript
is the module they should use.However, we don't get to control 3rd party packages and if these assume, behind their scene, that
js.document
exists, we might avoid breaking out of the blue by monkey-patching that on our side after we are sure we're running in a worker.@ntoll @JeffersGlass @antocuni @madhur-tandon @leriomaggio ... thoughts?
Beta Was this translation helpful? Give feedback.
All reactions