webcontainer-core icon indicating copy to clipboard operation
webcontainer-core copied to clipboard

This doesn't completely work offline.

Open real2two opened this issue 1 year ago • 7 comments

Is your feature request related to a problem? Please describe: In a numerous amount of pages, WebContainers claims to work when you're "offline". There's a catch though. WebContainers doesn't completely work offline. I'm not filling this out as a bug report because I don't know if it's intentional or not. image (from https://webcontainers.io/guides/introduction#webcontainers-versus-cloud-vm-approach)

For example: If your internet goes offline while you were testing on localhost and need to reload to see your changes, the WebContainer will no longer load, because: image

Another problem is when you want to load another port while you're offline. When you load a new port, the page won't load because it tries to load a new link (while you're offline). The reason why the page loads with the same port (while you're offline) is because it uses the same link and WebContainers works with PWAs.

I think it would be really useful if WebContainers completely worked offline (eg. electron apps), because I want to be able to build desktop application that can run offline and run user created scripts safely (eg. games).

Describe the solution you'd like: I can't really think of too many solutions, but here's one solution:

  • Allow self-hosting. This would be useful for desktop applications and local testing (eg. localhost). If you were to load WebContainers on a website, you'd already be connected to the internet, so that doesn't matter.

Describe alternatives you've considered: Not really.

Additional context: None

real2two avatar Mar 08 '23 02:03 real2two

this is what i absolutely need.

Aworldc avatar Mar 26 '23 06:03 Aworldc

Any progress on that?

cemalgnlts avatar Apr 11 '23 14:04 cemalgnlts

I also would like to make it work offline. Now it needs network to connect to stackblitz to request some resources like the following now.

image

Can we self host the static files and use webassembly like pyodide to serve some dynamic request locally. In this way, no serve resources needed.

More and more features and capabilities are moved to the local or browser, like WebGPU (see also https://mlc.ai/web-llm/) and so on. Maybe it's a new way to rethink or redesign the app.

liudonghua123 avatar Apr 25 '23 02:04 liudonghua123

I haven't dug into the files that are downloaded initially or on reload, but, when the stackblitz PWA is installed, couldn't the service worker implement a cache policy and proxy all of those fetch requests to the cache if the network response fails?

This is the strategy I've used for other "full offline" PWAs.

Unless something during runtime requires network access, I think that would do the trick.

alexjbuck avatar Apr 29 '23 11:04 alexjbuck

Hi! I also tried to make it completely offline without success. Load times can be drastically reduced by doing this. In my case, I'm just using a Vite server where files are loaded dynamically, but the rest of the files don't change every time, except maybe when Vite has a breaking change.

I hope this can be managed or fixed in some better way 🙏

image

thanks guys!

oceangravity avatar Jun 09 '23 10:06 oceangravity

Any progress on this? I am working on a learning environment which will be used in places where the internet connection will be either very slow or just not present. Would be very useful if I could use the library without the need of an internet connection.

K3BAP avatar Mar 23 '24 08:03 K3BAP

I think doing it completely offline will ensure that they can't make anything commercially out of the project. So I don't think they are very positive about it.

cemalgnlts avatar Mar 23 '24 09:03 cemalgnlts