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

web - support to load icons/resources contributed by extensions #75061

Closed
jrieken opened this issue Jun 7, 2019 · 23 comments
Closed

web - support to load icons/resources contributed by extensions #75061

jrieken opened this issue Jun 7, 2019 · 23 comments
Assignees
Labels
feature-request Request for new features or functionality verification-needed Verification of issue is requested verified Verification succeeded web Issues related to running VSCode in the web
Milestone

Comments

@jrieken
Copy link
Member

jrieken commented Jun 7, 2019

The web companion currently cannot load resources, like icons, because they are served from the remote extension host using the vscode-remote-scheme. There are three potentials approaches to tackle this

  1. more uri-transforming. we already know that this is challenging because uris often come as css-rules and we don't look at those strings
  2. patch document.createElement and have special cases for style and img tags (and others)
  3. use the mutation observer to know when a remote-resource is being requested

So, far option 1 seems tricky, option 2 seems pragmatic, and option 3 seems to be the browser way. There was also an attempt use service workers to serve such resources but only the https-scheme is supported...

cc @mjbvz who has a similar problem with webviews (and explored the service worker route)

@jrieken jrieken self-assigned this Jun 7, 2019
@jrieken jrieken added feature-request Request for new features or functionality web Issues related to running VSCode in the web labels Jun 7, 2019
@jrieken jrieken added this to the June 2019 milestone Jun 7, 2019
@jrieken
Copy link
Member Author

jrieken commented Jun 7, 2019

Using the mutation observer and blob-url. Should be possible to reduce flicker to a minimum but no guarantees as mutation observers are run outside the dom-loop.

Jun-07-2019 16-18-35

pull bot pushed a commit to Pandinosaurus/vscode that referenced this issue Jun 7, 2019
@mjbvz
Copy link
Collaborator

mjbvz commented Jun 10, 2019

Neat. I think service workers would perhaps be better for this, but as you note they only support https URIs so we'd have to switch away from using vscode-remote anyways.

Mutation observers may give us a somewhat reasonable story for migrating webview content back to the web, before we introduce some sort of proper api for webview extensions to use

pull bot pushed a commit to Pandinosaurus/vscode that referenced this issue Jun 19, 2019
this change makes style changes visible to the mutation observer
@mjbvz
Copy link
Collaborator

mjbvz commented Jun 21, 2019

For actual serving up of the resources themselves, I think the service worker based virtual server approach I've taken for serving up webview content could be used here too. Here's how it could work:

  1. Instead of using a unique protocol (vscode-remote), we rewrite remote resources to a unique endpoint (/vscode-remote/authority/path/to/resource) that still uses http or https.
  2. When running in the web, we register a service worker that handles requests to the special vscode-remote endpoint.
  3. The service worker uses postMessage to ask the main VS Code instance to resolve the resource
  4. VS Code resolves the requested resource and posts the result back to the service worker.
  5. The service worker then resolves the original request

I don't think we can register a service worker for desktop VS Code.

@jrieken
Copy link
Member Author

jrieken commented Jun 24, 2019

I like that. It will help with caching and will allow for a solution in which we rewrite url sync, e.g. instead of using the mutation observer approach I would like to have a place that uses remote-urls marked in code, using some special transformer-function like domresource.

@bpasero
Copy link
Member

bpasero commented Jun 24, 2019

Sounds good to me as well. We should validate if we can use the same trick in Desktop, would be nice.

@jrieken
Copy link
Member Author

jrieken commented Jun 24, 2019

We should validate if we can use the same trick in Desktop, would be nice

I'd say it depends on service workers be available for desktop mode...

@bpasero
Copy link
Member

bpasero commented Jun 24, 2019

@deepak1556 are you aware of any restrictions in Electron to use service workers?

@jrieken jrieken modified the milestones: June 2019, July 2019 Jun 24, 2019
@bpasero
Copy link
Member

bpasero commented Jun 24, 2019

I just verified that (in Electron 4) I can register a service worker on the file:// scheme:

image

However I am not sure why issues such as electron/electron#13740 are still open?

@deepak1556
Copy link
Collaborator

Service worker support on desktop is same as web for http(s) schemes, as for custom protocols it works if the scheme is registered with privileges using https://github.com/electron/electron/blob/master/docs/api/protocol.md#protocolregisterschemesasprivilegedcustomschemes .

When it comes to file protocol, electron managed to hook into the service worker registration and get it working, but I would highly suggest not to rely on it because its an origin less scheme , there is less flexibility with caching and worker registration per document.

@bpasero
Copy link
Member

bpasero commented Jun 24, 2019

@deepak1556 ok, so we can introduce a custom protocol for Desktop and register it as being privileged. Is there any disadvantage from doing this registration?

@deepak1556
Copy link
Collaborator

Nope no disadvantage, just make sure that in electron < 5 , we need to setup privileges using two different apis for service workers to work properly.

Things are much better after 5 where they are unified into one single api d814104

@bpasero
Copy link
Member

bpasero commented Jun 24, 2019

Thanks for clarifying this.

kiku-jw added a commit to kiku-jw/vscode that referenced this issue Jun 26, 2019
* beautify macos keyboard layout label

* Open folders and workspaces in new windows

* Basic file opening via Open File command

* Update auto detect layout info.

* Respect openFoldersInNewWindow setting for folders/workspaces

* Make openWindow function resolve at right time

* keyboard layout status bar item tooltip

* Move workspace menu and action to fileActions.contribution

* Add clarifying comment on instance service request events

* Fullscreen change event.

* Remove unneeded margin on settings editor scrollbar
Fix microsoft#75724

* fix: microsoft#72626

* Remove extra register of automatic tasks

Fixes microsoft#75758

* remove trailing '/' from repo url for baseFolderName

* handle style-attribute modifications, cache requests in addition to results, microsoft#75061

* fix microsoft#75818

* fix bad tree guide indentation

* remove TODO

* update eslint

* update distro

fixes microsoft#73872

* Revert "Revert "Merge pull request microsoft#75695 from orange4glace/master""

This reverts commit a05e05c.

* Revert "Revert "explorero: file actions disablment no longer needed""

This reverts commit b634152.

* more code insets API tweaks, microsoft#66418

* Alpine build

* Update distro hash

* Remove duplicate cp

* shellscript: Add folding markers

* fixes microsoft#75829

* show setting on windows only

* add ExtensionKind and remoteName propsed APIs, microsoft#74188

* debt - use file service based configuration file service

* fix tests

* debt create configuration file service inside configuration service

* First cut of file service based user data service

* Use user data service for reading settings

* Update distro hash

* add diagnostic tool for git file event issues

* 💄

* Update distro hash

* introduce VSCODE_STEP_ON_IT

* remove env scripts

fixes microsoft#74792

* Update xterm.css

Fixes microsoft#75827

* check if file exists

* remove alert, aria-live will read the content even with no focus

fixes microsoft#41356

* win code.sh fix

* 🧀 Fix microsoft#75831

* Add proposed api check for shell API

Part of microsoft#75091

* launch ext host window internally

* EH debugging: support multiple files and folders

* Update distro

* xterm@3.15.0-beta50

Diff: xtermjs/xterm.js@846a189...96eafd3

Changes:

- Publish improvements
- Layering/strict updates

* Fire onDidChangeMaximumDimension when dimensions are set

Fixes microsoft#73496

* Fix potential race

* Delete cached service worker entries after a short timeout

* Fix webview developer command not being registered

* Re-queue canceled geterr requests before remaining buffers

We should give higher priority to files that have previously had geterr triggered on them but did not have their request completed

* Remove log uploader

Fixes microsoft#75748

* Use localized name for macOS keyboard layout

* fixes microsoft#75856

* User keyboard layout

* simplify common keymap layer

* load user keyboard layout after initialization

* US Standard keyboard info

* better score for layout

* fast return keyboard layout if 48-keymap matches

* a single keyboard event can be a keymap

* switch to user selected keyboard layout

* Have `.get` return promise directly

* Make sure we wait until service worker is ready before creating content

* Add version check to service worker

Try to make sure our page is talking to the expected version of the service worker

* Don't use clone as much

* Move host javascript to own file

* Update distro

* Remove icon explorations before shipping stable

* Move listener to window service.

* Minimap: Render find match decorations, fixes microsoft#75216

* Fix `navigator.serviceWorker.ready` is a Promise, not a function

* Use update instead of manually tring to re-register

* Extract ITypeScript server interface

* extract server error to own file

* Extract server spanwer to own file

* Renames

* Move getQueueingType into class

* Add experimental dual TS server

Fixes microsoft#75866

* Enable "typescript.experimental.useSeparateSyntaxServer" for VS Code workspace

* Remove trailing comma

* Include server id in TS server errors

* Make execute command a configuration object

* Also include format in the syntax commands

* Fix method name

* Renames

* Better encapsulate logic of spawning different server kinds

* some fixes for mac web

* New test runner API for microsoft#74555

* update doc, microsoft#74188

* build: release only iff all builds succeed, introduce VSCODE_RELEASE env

* first version of vscode.workspace.fs

* 💄

* Tasks registration + the local ext host now has an autority

Part of microsoft/vscode-remote-release#757

* Add platform override to getDefaultShellAndArgs in terminal

Part of microsoft/vscode-remote-release#757

* Ensure no trailing path separtor on URIs from file picker

Part of microsoft#75847

* data tree view state should store scrollTop, microsoft#74410

* fix microsoft#75564

* Change promise structure of creating terminal in tasks

Potential fix for microsoft#75774

* do not allow additionalProperties

microsoft#75887

* explorer: roots forget children on new file system provider registration

microsoft#75720

* Update max tokenization limit without reload

* Use interfaces for keyboard layout registration

* Separate keyboard layout loading logic for testing

* Test browser keymapper

* unused standard keyboard event.

* Make sure we dismiss the zoom status bar entry when switching editors

* Reduce state

* Added strictly typed telemetry function (microsoft#75915)

* Added strictly typed telemetry function

* cleanup publicLog2 signature

* Extract port mapping helper function

* Re-use extractLocalHostUriMetaDataForPortMapping for openUri

* Also map 127.0.0.1 in webviews and forward it for openExternal

Fixes microsoft/vscode-remote-release#108

* use empty model when content is empty

* 💄

* Update keyboard layout file comments

* Delete breadcrumbs.filterOnType unused setting. Fixes microsoft#75969

* Add quick open/input color registrations (fixes microsoft#65153)

* Update API

* implements ExtHostEditorInsetsShape

* use divs for tree indent guides

fixes microsoft#75779

* comment out more (for microsoft#74898)

* Quick Open > Quick Input (microsoft#65153)

* build - enable language server tests again (for microsoft#74898)

* use polish for wsl1

* move extension kind to Extension-interface

* init log level of remote log service

* Open/Save local commands should not show in the command palette

Fixes microsoft#75737

* chockidar: use polling

* fix build conditions

* xterm fixes for cglicenses

* oss 1.36.0

* workaround for microsoft#75830

* update distro commit

* electron - still call setBounds() as workaround for first window

* fixes microsoft#75753

* node-debug@1.35.3

* remove user data service

* use posix.join

* update doc

* Add -1 tab index to status bar entries

This keeps them out of the tab order, but allows them to be read with a screen reader

Fixes microsoft#41406

* empty view polish labels for remote case

microsoft/vscode-remote-release#511

* send remote watcher error to file service (fixes microsoft/vscode-remote-release#329)

* update distro

* better error handling in case of loader error in tests

* fix win 32 bits unit tests

* electron@4.2.5 (microsoft#76020)

* Code-insiders started from WSL doesn't return to console/ doesn't connect. Fixes microsoft/vscode-remote-release#780

* Group decorations by line before rendering

* disable support for simple fullscreen (microsoft#75054)

* telemetry - add window.nativeFullScreen

* move API to stable,  microsoft#74188

* build - add and use --disable-inspect for integration tests (microsoft#74898)

* 💄

* bump distro

* Report workspace stats in shared process

* Make return undefined explicit

* Add missing return

* Use explicit window.createWebviewManager

* gdpr comments

* webkit fullscreen detection

* Fix file name spelling

* update distro

* add logging

* disabling installing extension from gallery when not enabled

* status.workbench.keyboardLayout

* Move Inspect Keyboard Layout JSON to workbench

* return local extension after install

* install deps and packs while installing from gallery

* Fix default shell selector outside of Windows

Fixes microsoft#76040

* Add explicit win32 gheck for using user specific temp folder

* Always use settings UI when querying online services, fixes microsoft#75542

* Disable conpty in terminal when accessibility mode is on

Fixes microsoft#76043

* Move the webviewResourceRoot property to be set on each webview instead of as a global property

For microsoft#72155

This allows  us to potentially change the resource root per webview

* Make RelativeWorkspacePathResolver  a static class

* Use openExternal

* Auto restart when changing  typescript.experimental.useSeparateSyntaxServer

* Fix regular expression for rewriting iframe webview html replacing quotes

* Telemetry Command (microsoft#76029)

* Added telemetry command

* Initial Build support

* Added build logic for telemetry

* Linux Builds

* Windows builds sort of work

* Remove arm telemetry extraction

* Remove alpine telemetry extraction

* Remove accidental s

* More try catch

* Use full resource uri for transforming webview resources

This ensures we still work even if there is no base uri set

* Use outerHtml to make sure we write `<html>` element from extensions too

* Use a regexp that works across browsers

* Implement reload on iframe based webview Elements

* fix various nls issues

* 💄

* add debug output (microsoft#76024)

* Fix tasks platform for quoting

Fixes microsoft#75774

* fix hockeyapp symbols and report errors (fix microsoft#76024)

* update distro

* fix bad watch

* update distro

* Fix drive letter casing on typescript tasks

Occurs when opening by double clicking on workspace file. Fixes microsoft#75084

* update distro

* update distro

* Test remoteName and extensionKind (for microsoft#76028)

* MainThreadFileSystem does not await

* Fix microsoft#76096

* Rename runInBackground to hideFromUser

See microsoft#75278

* Update distro

* Fix minimap decoration rendering on horizontal scroll, fixes microsoft#76128

* Handle windows paths correctly when loading webvie resources

* Fix standard link handler for iframe based webviews

* Mark extensions.all as readonly

This iteration, we marked a few other arrays as readonly. We should do the same for extensions.all

* Fix microsoft#75927.

* Register mouse down on container dom node.

* Make sure we never cancel a request to just one of the ts servers

Fixes microsoft#76143

* Show document link tooltip first and put click instructions in parens

Fixes microsoft#76077

This change also update our standard link hovers to follow this format

* reset listener once users choose a dedicated keyboard layout

* switch to a new layout only when the score is higher.

* Fix kb unit test

* fix microsoft#76149

* web - document some API

* 💄 workbench API

* disable arm and alpine for stable

fixes microsoft#76159

* Fix extra auto complete on fast delete (microsoft#74675)

Fixes #vscode-remote-release/4

* use yarn --frozen-lockfile for builds

* remove `update.enableWindowsBackgroundUpdates` from online settings

* fix microsoft#76076

* revert the change

* prevent product.json containing gallery

* fix microsoft#76074

* fixes microsoft#54084

* Fix microsoft#76105

* fix microsoft#75904

* workaround for  microsoft#74934
@mjbvz
Copy link
Collaborator

mjbvz commented Jun 28, 2019

Here's the service-worker we use for loading local resources inside of webviews:

/*---------------------------------------------------------------------------------------------

We'll need to register a new worker for VS Code itself but may be able to reuse some of this code. The lifecycle and versioning of service workers can be complicated so we'll want to make sure VS Code is always talking to the expected version of the worker. I've added some initial logic in the webview service worker to handle this bu haven't tested it too much yet

@jrieken
Copy link
Member Author

jrieken commented Jun 28, 2019

Yeah, that's good start. Tho we should have a service worker that we author in TypeScript and its own compilation artefact (just like web-workers).

Things we should/could use the "main" service worker for

@bpasero
Copy link
Member

bpasero commented Jun 28, 2019

@jrieken @mjbvz one thing to keep in mind is that you can only have 1 service worker per domain, so I feel like we need another set of API facade and component for the hoster to use as part of their service worker infrastructure. In other words, we should not bring up the service worker, the hoster needs to imho.

@jrieken
Copy link
Member Author

jrieken commented Jun 28, 2019

In other words, we should not bring up the service worker, the hoster needs to imho.

I think that will make development very slow. So much internal knowledge and tech will be built into this that I don't think it will be feasible, esp. not at first.

@jrieken
Copy link
Member Author

jrieken commented Jun 28, 2019

one thing to keep in mind is that you can only have 1 service worker per domain

You can have multiple per domain but they need to tackle different scopes. So, we can claim specialised scopes, like web view, for us and see if there is an opportunity for 'shared' service workers.

@bpasero
Copy link
Member

bpasero commented Jun 28, 2019

You can have multiple per domain but they need to tackle different scopes.

Ok, I did not know that 👍

@jrieken
Copy link
Member Author

jrieken commented Jul 4, 2019

Now on master: contributed URIs, e.g icons or theme files, not go through dom#asDomUri before being inserted into the dom. That util synchronously checks for the vscode-remote-uri and rewrites them to <window.location>/vscode-resources/fetch?<actual_uri>. Those uris are served from a service worker which uses a cache or the render's file service to fullfill the request (as described here #75061 (comment)). Open questions/work:

  • Cache invalidation - all resources are now cached and we need to know when to invalidate those caches...
  • How to sync with the SW becoming available - the SW has its own lifecycle and asDomUri might have been called already without the SW intercepting those requests. We should consider also service these request from our server or we block the workbench on the SW being available...
  • Make this work for the web and desktop - this is debt as today the desktop has a main-thread handler which we should get rid off.

@bpasero
Copy link
Member

bpasero commented Jul 4, 2019

We should consider also service these request from our server or we block the workbench on the SW being available...

We could add this to the server however I somewhat like that we currently fully rely on the service worker to do its business so that we can validate it actually works. I feel like we should maybe leave it like that for a bit longer to really stress test the solution.

I feel like the service worker - once activated - should talk to the tab and ask it to re-resolve any URI that was going through the asDomUri method, similar to what the mutation observer did before.

@jrieken
Copy link
Member Author

jrieken commented Jul 4, 2019

I feel like the service worker - once activated - should talk to the tab and ask it to re-resolve any URI that was going through the asDomUri method, similar to what the mutation observer did before.

Yeah, that and just start the SW sooner, e.g while code loading for the workbench happens. Last, while debugging I have seen that images/resource that the service worker is going to intercept magically recover. It seems that the browser initiates another request once the service worker is ready. Tho that's only an observation and nothing I am certain about...

@jrieken
Copy link
Member Author

jrieken commented Jul 8, 2019

I have created electron/electron#19150 which tracks Electron crashing when trying to load a service working from a custom scheme. fyi @deepak1556

@jrieken
Copy link
Member Author

jrieken commented Jul 11, 2019

This is now mostly done and remaining pieces will be tracked as follow-up items

@jrieken jrieken closed this as completed Jul 11, 2019
jrieken added a commit that referenced this issue Jul 22, 2019
@roblourens roblourens added the verification-needed Verification of issue is requested label Jul 30, 2019
@lramos15 lramos15 added the verified Verification succeeded label Jul 30, 2019
@vscodebot vscodebot bot locked and limited conversation to collaborators Aug 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality verification-needed Verification of issue is requested verified Verification succeeded web Issues related to running VSCode in the web
Projects
None yet
Development

No branches or pull requests

6 participants