Implementing a SharedArrayBuffer fallback via config.toml #2333
Replies: 3 comments 4 replies
-
UpdateI have created a monkey-patched PoC that shows that we can run sabayon on PyScript .com and see stuff working on Safari too: The proposal here is to orchestrate that patching out of the box in core where we have more control, we can lazy load dependencies only when/if needed, we don't need users to think too much about anything on PyScript .com if we can provide that I am more and more convinced this is the way to go so that we can support all users and, most importantly, iOS users too. |
Beta Was this translation helpful? Give feedback.
-
On the other hand ...As I've proven the polyfill works as expected on PyScript .com, I start wondering if we could start "simple" by allowing that Pinging you again to be sure this makes sense as initial effort and as a way to move forward with this topic and not block @JoshuaLowe1002 PyScript updates: would you agree on having such @ntoll @danyeaw @mchilvers @FabioRosado @fpliger + whoever has an opinion around this topic 👋 |
Beta Was this translation helpful? Give feedback.
-
This looks great! I tested your demo myself on Safari on iOS and all works. I might be missing something here, but is there a reason we wouldn't just reuse the existing service-worker attribute on the script tag for the existing sabayon fallback? That being said, I do think this could be better in config. Seems like a more natural home than an attribute. |
Beta Was this translation helpful? Give feedback.
-
Edit
Keeping the original discussion for reference/history sake but I ended up explaining why some part of this idea won't work in this MR which has been already tested as working fine #2334
Basically, a polyfill needs to be imported before other scripts and just waiting for scripts on the DOM to optionally have a
service-worker
attribute, or even waiting for any Worker (Workers are patched by the polyfill, you can see where this is going) to receive or use thatservice-worker
detail, is alway too late to actually fix the broken environment.My current implementation there provides a different approach:
@pyscript/core/service-worker
utility/helper right before you land@pyscript/core
in your pageI hope you also like the current approach and I think we need to document this new requirement for whoever was using the
service-worker
attribute, something we documented too, something I've thought nobody was using ... right now this seems to work fairly well and definitively better than before so maybe we can also remove that big warning from the docs.The TL;DR reason for discussing this topic is that we currently do not support Safari Desktop and Safari Mobile on PyScript .com but the issue around headers expectations, how these could limit any App potential (to work also in Safari) and all topics around this fundamental requirement are way more common than expected and for good reasons:
Cross-Origin-Embedder-Policy: require-corp
is used to enable Safari, most embedded stuff and third party scripts, CDNs or services might not work as expected. This was the initial reason to introduce a fallback in PyScript but that fallback was never too popular, although we've recently realized one of the most successful projects based on PyScript was, in fact, using such fallbackdocument
andwindow
(or, in general, the DOM) cannot be used when such headers are not around ... yet "what if" we could enable everything, acknowledging that it's going to be inevitably slower and yet it would work occasionally, when those synchronous operations are needed?A SharedArrayBuffer Polyfill
Meet sabayon and its latest polyfill variant:
Atomics.wait
andAtomics.notify
that "just work"™️ ... but ...Cross-Origin-Opener-Policy: same-origin
and/orCross-Origin-Resource-Policy: cross-origin
and it doesn't needCross-Origin-Embedder-Policy
neither: it uses the ServiceWorker to orchestrate a synchronous XHR request to that file itself and it's been proven to work already (as in: that is what people have been using so far without major complains)crossOriginIsolated
global reference is alreadytrue
Proposal
We add that conditional bootstrap logic for sabayon as fallback so that:
/__pyscript_sw_fallback.js
... @mchilvers and @FabioRosado can we do that?pyscript_sw_fallback = "/path_to_sw.js"
as a config property and we automatically decide, when it's present and desired, to bootstrap sabayon polyfillThe goal of this proposal in a nutshell:
Cross-Origin-Embedder-Policy: credentialless
is in place@ntoll, @danyeaw and @fpliger ... what do you all think about this proposal?
Beta Was this translation helpful? Give feedback.
All reactions