-
Notifications
You must be signed in to change notification settings - Fork 29.2k
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
Allow for webviews to run service workers #194751
Comments
Have you tried using an iframe inside the webview pointing the a domain you control? That should allow service workers to be active inside of the iframe. This is essentially what we do to implement webviews |
Maybe something like this:
At this point the iframe contents are now controlled by the service worker. The iframe is also able to communicate back with its parent webview using post message Then to load custom html inside of the iframe:
This does require hosting content at |
@mjbvz Thanks for the clarification. Yeah that external domain is what I thought you might have been suggesting. Right now our tool really is an online tool, but we've been trying to build around the possibility that we might deploy in learning environments (school / prisons, ect...) where adding in more domains to connect to might be restricted. So it's nice to know that with your suggestion we might have a reasonable option as long as we're ok with hosting it ourselves. We have plans to host student content for sharing at some point so we'll probably have to tackle that anyways. One more small question, was this behavior expected?
It made sense to me that content hosted inside an iFrame would not be able to resolve webview URIs, but I was a bit surprised that the iFrame element itself couldn't resolve that, since I considered that element at the same level as the img. |
Our web extension is looking to allow for previewing HTML files in a VS Code webview in scenarios where the HTML file and content is hosted in local storage as opposed to hosted online. The target HTML is hosted in an iFrame inside a small wrapper main webview HTML.
To do this, we want to provide a service worker in our webview to intercept fetch calls so that our extension can handle the file requests and load and return the resources from local storage. However we've been unable to get a service worker hosted in a VS Code webview, both at the top level wrapper HTML and by trying to register it in the target hosted HTML.
When looking into service workers I believe that the following is true:
So far the things that I've attempted I have all ended up essentially here:
I create an asWebviewUri pointing at the file of our service worker (which is added to a location accessible in localResourceRoots) but due to the origin difference the service worker can't be loaded, either here at the top level of the webview or in the iFrame hosted below.
Given what I've seen I don't think that what I'm looking to do is possible now, but if it could be enabled it would be very helpful for our scenario.
The text was updated successfully, but these errors were encountered: