Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can service worker support IPFS? #60

Open
LiNk-NY opened this issue Feb 29, 2024 · 2 comments
Open

can service worker support IPFS? #60

LiNk-NY opened this issue Feb 29, 2024 · 2 comments
Assignees

Comments

@LiNk-NY
Copy link

LiNk-NY commented Feb 29, 2024

Thank you for working on this exciting tech!

I was wondering if it is possible to host a shinylive app via IPFS https://ipfs.tech/ ?

In theory, it should work with a localhost connection?

I am only beginning to understand the infrastructure but in my testing, I get an error that says:

Shinylive uses a Service Worker, which requires either a connection to localhost, or a connection via https.

which seems to come from

// src/load-shinylive-sw.ts
var localhostNames = ["localhost", "127.0.0.1", "[::1]"];
if (window.location.protocol !== "https:" && !localhostNames.includes(window.location.hostname)) {
  const errorMessage = "Shinylive uses a Service Worker, which requires either a connection to localhost, or a connection via https.";
  document.body.innerText = errorMessage;
  throw Error(errorMessage);
}

The URL to the example app looks something like:

http://bafybeidqxcurjbnkahltgppzfwwcp6te2ncz426at3675vbebalxppe454.ipfs.localhost:8080/?filename=index.html

I'm using a native IPFS browser (Brave) connected to a local IPFS node.

Other experiments using Joe Cheng's example (fork here) seem to render only the text:

http://bafybeica5jbha66yt3mq34j4ndbxd74gg4idzfesblc5x3ncqnnvowdjzu.ipfs.localhost:8080/?filename=R-shinylive-demo.html

FWIW, the R-shinylive-demo.html was rendered with the #| standalone: true option.

Is this something that is possible?

Thank you!

@LiNk-NY
Copy link
Author

LiNk-NY commented Nov 21, 2024

Any updates / comments? @schloerke @jeroen

@georgestagg
Copy link
Collaborator

Unfortunately, I don't think this is currently possible.

As described in the error message shown,

Shinylive uses a Service Worker, which requires either a connection to localhost, or a connection via https.

Shinylive works by intercepting network requests using a Service Worker. For security reasons, the service worker API is only enabled by web browsers when connecting to the localhost origin, or when using the https:// protocol.

It looks like from the sample URLs that IPFS servers are using http://. So, to be considered a secure context connections must be through localhost. I'm not 100% sure if these long subdomains of localhost are counted by the browser as a secure context or not, but a stack overflow answer suggests that they do not count and so the Service Worker API cannot be used here.


The only thing I can think of that would allow this to work is to explicitly disable the browser security restrictions using command line launch flags. While possible, it is not a real solution as it would require every user to launch a web browser with extra flags and disabling security restrictions in general is a very bad idea. Nevertheless, more information is available on how this can be done for testing purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants