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

window.SharedArrayBuffer will disappear in webviews soon #116715

Closed
Tyriar opened this issue Feb 15, 2021 · 19 comments
Closed

window.SharedArrayBuffer will disappear in webviews soon #116715

Tyriar opened this issue Feb 15, 2021 · 19 comments
Assignees
Labels
electron Issues and items related to Electron electron-17-update Issues related to electron 17 update engineering VS Code - Build / issue tracking / etc. feature-request Request for new features or functionality on-release-notes Issue/pull request mentioned in release notes on-testplan sandbox Running VSCode in a node-free environment

Comments

@Tyriar
Copy link
Member

Tyriar commented Feb 15, 2021

FYI In Chrome 91, SAB will no longer exist on window unless cross origin isolation is enabled: https://developer.chrome.com/blog/enabling-shared-array-buffer/. This change may cause bugs in extensions that use SharedArrayBuffer with falling back to ArrayBuffer.

In order to eventually support SAB for web workers in webviews (#87282) this will probably need to be an opt-in setting in WebviewOptions.

@mjbvz mjbvz added this to the March 2021 milestone Feb 17, 2021
@mjbvz mjbvz modified the milestones: March 2021, April 2021 Mar 19, 2021
@mjbvz mjbvz modified the milestones: April 2021, May 2021 Apr 20, 2021
@Tyriar
Copy link
Member Author

Tyriar commented May 8, 2021

FYI @deepak1556, this should block the Electron update when it goes to m91 since I believe accessing SharedBufferArray will cause an exception, likely breaking many webviews using libs.

@Tyriar Tyriar added the electron Issues and items related to Electron label May 8, 2021
@deepak1556 deepak1556 self-assigned this May 9, 2021
@deepak1556 deepak1556 added electron-blocker Issues in next update of Electron preventing update electron-13-update Issues related to electron 13 update labels May 9, 2021
@deepak1556
Copy link
Collaborator

I have to look into what needs to be done for cross-origin isolation with iframe based webviews and the workbench. But given our workbench will soon be on a custom protocol, this should be possible. I will update with more info in May debt week.

@mjbvz mjbvz modified the milestones: May 2021, June 2021 May 21, 2021
@Tyriar
Copy link
Member Author

Tyriar commented Jun 7, 2021

@mjbvz I've started hitting this in codespaces on Edge, some things just don't work anymore as there's no fallback yet if SAB isn't there. This isn't an easy thing to do as well since the workers Luna Paint use are built around SAB

687.js:1 Uncaught (in promise) ReferenceError: SharedArrayBuffer is not defined
    at p._startMove (687.js:1)
    at pointerDown (687.js:1)
    at vscode.main.js:1
    at n.fire (vscode.main.js:1)
    at HTMLDivElement.<anonymous> (vscode.main.js:1)

@mjbvz
Copy link
Collaborator

mjbvz commented Jun 10, 2021

@Tyriar For codespaces, the codespaces team will need to change the code spaces host page, correct? Not sure if that will cause issues for other webview functionality though

@Tyriar
Copy link
Member Author

Tyriar commented Jun 11, 2021

Yeah you're right, reporting to them.

@deepak1556 deepak1556 modified the milestones: June 2021, July 2021 Jun 28, 2021
@deepak1556 deepak1556 removed this from the July 2021 milestone Jul 19, 2021
@deepak1556 deepak1556 added electron-14-update and removed electron-13-update Issues related to electron 13 update labels Jul 19, 2021
@corwin-of-amber
Copy link

This seems to be a problem in renderer processes too. Or am I missing something? Is there a straightforward way to set the COOP/COEP headers in the renderer process when it uses a file:// schema?

@deepak1556
Copy link
Collaborator

@corwin-of-amber you cannot set those headers for file protocol but if you were to use a custom standard protocol https://github.com/electron/electron/blob/main/docs/api/protocol.md#protocolregisterschemesasprivilegedcustomschemes then you will be able to provide those headers.

@corwin-of-amber
Copy link

Thanks @deepak1556 ! Looks a bit hefty just to get SharedArrayBuffer but there seem to be other benefits too.

@PaulOrlov
Copy link

The SharedArrayBuffer does not work ("SharedArrayBuffer is not defined") in the renderer already for Electron 14

@Tyriar
Copy link
Member Author

Tyriar commented Sep 9, 2021

FWIW I made Luna Paint resilient to this which means it works again in Codespaces. Since workers aren't supported in webviews anyway yet (#87282) this should be able to be worked around in the extension with:

if (!('SharedArrayBuffer' in window)) {
  (window as any).SharedArrayBuffer = ArrayBuffer;
}

It would be nice to fix this in Electron 14 as it's inconvenient to add the above workaround when we could build it into core, and technically a breaking change.

@deepak1556
Copy link
Collaborator

This requires a bit of replicating the work done for the web application.

@mjbvz what are the COOP and COEP headers set for webview on the web ? Also, is this behind an opt-in setting on the web ?

Also can we limit this to only for web worker based extensions ? This is to make sure we don't allow passing these shared buffers to other privileged processes when the renderer is sandboxed.

@deepak1556 deepak1556 added the sandbox Running VSCode in a node-free environment label Sep 10, 2021
@Tyriar
Copy link
Member Author

Tyriar commented Sep 10, 2021

Also can we limit this to only for web worker based extensions ?

@deepak1556 do you mean webview based extensions?

This is to make sure we don't allow passing these shared buffers to other privileged processes when the renderer is sandboxed.

If it would be possible to pass a SAB from a webview to the extension host in the desktop case that would be amazing, if so and it's a security concern, perhaps we should allow opting into this in the package.json and warning on extension install or something? The win that this would give would be huge:

  • No more transferring many MBs of image data back and forth which locks up the webview UI thread
  • I could enable hot exit/backup for most images (unless they're enormous) as transferring the data would be instant
  • Coupled with worker support, encoding could be done there which would let me add a responsive loading bar to the webview and the final save transfer would be super fast

@mjbvz mjbvz added the bug Issue identified by VS Code Team member as probable bug label Oct 11, 2021
@deepak1556 deepak1556 added electron-16-update Issues related to electron 16 update and removed electron-15-update labels Nov 18, 2021
@601355640
Copy link

import { session } from 'electron'
session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
callback({
responseHeaders: {
...details.responseHeaders,
'Cross-Origin-Opener-Policy': 'same-origin',
'Cross-Origin-Embedder-Policy': 'require-corp',
}
})
})

@7ombie
Copy link

7ombie commented Jan 26, 2022

Can we share a SharedArrayBuffer between the renderer context and the node context?

@deepak1556 deepak1556 removed the electron-blocker Issues in next update of Electron preventing update label Feb 2, 2022
@deepak1556 deepak1556 added electron-17-update Issues related to electron 17 update and removed electron-16-update Issues related to electron 16 update labels Mar 17, 2022
@jrieken jrieken self-assigned this Mar 21, 2022
@jrieken jrieken added feature-request Request for new features or functionality engineering VS Code - Build / issue tracking / etc. and removed bug Issue identified by VS Code Team member as probable bug labels May 3, 2022
@jrieken jrieken modified the milestones: On Deck, August 2022 Jul 14, 2022
@jrieken jrieken modified the milestones: August 2022, September 2022 Aug 24, 2022
@jrieken
Copy link
Member

jrieken commented Sep 6, 2022

This is now implemented but because of potential breakage must be explicitly enabled with the --enable-coi command line flag

@jrieken jrieken closed this as completed Sep 6, 2022
@safasofuoglu
Copy link

@jrieken could you clarify whether your implementation covers @Tyriar 's use case:

If it would be possible to pass a SAB from a webview to the extension host

And if not, whether it's possible at all through further work?

@mmis1000
Copy link

mmis1000 commented Sep 6, 2022

Is that even physically possible if extension host and webview can live in different machine? In some case like ssh remote, extension may lives in remote host but webview is always on local.

@jrieken
Copy link
Member

jrieken commented Sep 7, 2022

It depends on the what extension host you are dealing with: There is the local nodejs-based extension hot, there is remote extension host (ssh, wsl, docker, etc), and there is the local webworker-based extension host. I haven't tested any of this but the former two aren't supported (different processes/machines) but the latter should be possible (e.g web worker to web view)

@jrieken jrieken added the on-release-notes Issue/pull request mentioned in release notes label Oct 1, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Oct 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
electron Issues and items related to Electron electron-17-update Issues related to electron 17 update engineering VS Code - Build / issue tracking / etc. feature-request Request for new features or functionality on-release-notes Issue/pull request mentioned in release notes on-testplan sandbox Running VSCode in a node-free environment
Projects
None yet
Development

No branches or pull requests