Skip to content

Commit af754ef

Browse files
authored
Add web command to request usb access (microsoft#151795)
This experimental command triggers a request for usb devices. After the user selects these, extensions under the extension host can access them using `navigator.usb.getDevices(...)`
1 parent 2e3c24c commit af754ef

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/vs/workbench/browser/actions/workspaceCommands.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { IOpenEmptyWindowOptions, IOpenWindowOptions, IWindowOpenable } from 'vs
2424
import { IRecent, IWorkspacesService } from 'vs/platform/workspaces/common/workspaces';
2525
import { IPathService } from 'vs/workbench/services/path/common/pathService';
2626
import { ILocalizedString } from 'vs/platform/action/common/action';
27+
import { isWeb } from 'vs/base/common/platform';
2728

2829
export const ADD_ROOT_FOLDER_COMMAND_ID = 'addRootFolder';
2930
export const ADD_ROOT_FOLDER_LABEL: ILocalizedString = { value: localize('addFolderToWorkspace', "Add Folder to Workspace..."), original: 'Add Folder to Workspace...' };
@@ -306,3 +307,9 @@ CommandsRegistry.registerCommand('_workbench.getRecentlyOpened', async function
306307

307308
return workspacesService.getRecentlyOpened();
308309
});
310+
311+
if (isWeb) {
312+
CommandsRegistry.registerCommand('workbench.experimental.requestUsbDevice', async (_accessor: ServicesAccessor): Promise<void> => {
313+
await (navigator as any).usb.requestDevice({ filters: [] });
314+
});
315+
}

src/vs/workbench/services/extensions/browser/webWorkerExtensionHost.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ export class WebWorkerExtensionHost extends Disposable implements IExtensionHost
130130
const iframe = document.createElement('iframe');
131131
iframe.setAttribute('class', 'web-worker-ext-host-iframe');
132132
iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin');
133+
iframe.setAttribute('allow', 'usb');
133134
iframe.setAttribute('aria-hidden', 'true');
134135
iframe.style.display = 'none';
135136

0 commit comments

Comments
 (0)