Web Extensions: How to access query string parameter? #2839
Replies: 2 comments
-
|
Hi @thecopy , I don't see a query string when you play with vscode.dev, so I'm not sure where/how you would access it. Either way, VS Code API abstracts the folder you have opened via Hope this helps |
Beta Was this translation helpful? Give feedback.
-
|
Hello! For web extensions in VS Code, you can access query string parameters through the const uri = vscode.env.uri;
if (uri && uri.query) {
const urlParams = new URLSearchParams(uri.query);
const folderParam = urlParams.get('folder');
if (folderParam) {
const data = await fetch(`https://api.example.com/data/${folderParam}`);
}
}Alternative approach using the active text editor: const workspaceFolders = vscode.workspace.workspaceFolders;
if (workspaceFolders && workspaceFolders.length > 0) {
const currentFolder = workspaceFolders[0];
}Important notes:
This method gives you clean access to URL parameters while maintaining compatibility across VS Code platforms. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
Im developing a web extension and would like to read the QS parameter from the extension code.
windowis not defined, how would i get access to it?My ultimate goal is to read e.g.
?folderand my extension will usefetchto download data from an external source based on the QS valueThanks!
BR
Beta Was this translation helpful? Give feedback.
All reactions