microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.47k stars 29.36k forks source link

URL fails to open while using vscode.env.openExternal function. #230921

Open sahuroshan opened 1 month ago

sahuroshan commented 1 month ago

Hi , I am facing one issue while using this function . The function opens a popup and when I Copy the link(using Copy button) and open it in browser it works but when I click on the Open button the link fails to open.

I see there is difference in URL in Copy and Open button. Image

URL from Copy button - https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fcanaccount.blob.core.windows.net%2Fron%2FARMTemplate-AzureSqlDatabase-DESKTOP-7MVF2-MSSQLSERVER02-2024-10-09-17-38-07.json%3Fsv%3D2023-08-03%26ss%3Db%26srt%3Dsco%26spr%3Dhttps%26st%3D2024-10-09T12%253A08%253A07Z%26se%3D2024-10-09T12%253A38%253A07Z%26sp%3Drwdlacupi%26sig%3Dx6HABHCXOcijCho56rs%252B0ltBhJehBBdNDM66xf1858E%253D

URL from Open button - https://ms.portal.azure.com/#create/Microsoft.Template/uri/https%253A%252F%252Fcanaccount.blob.core.windows.net%252Fron%252FARMTemplate-AzureSqlDatabase-DESKTOP-7MVF2-MSSQLSERVER02-2024-10-09-17-39-39.json%253Fsv%253D2023-08-03%2526ss%253Db%2526srt%253Dsco%2526spr%253Dhttps%2526st%253D2024-10-09T12%25253A09%25253A39Z%2526se%253D2024-10-09T12%25253A39%25253A39Z%2526sp%253Drwdlacupi%2526sig%253DBdbbPUAkUGbv4HZN6Asmq7%25252BXlsJbdt5OJPTJz9Kdhcc%25253D

I am using the below code to generate URI- private DeployToAzure(deployToAzureUrl: string) { deployToAzureUrl = encodeURIComponent(deployToAzureUrl); let scheme = 'https'; let authority = 'portal.azure.com'; let path = '/'; let fragment = 'create/Microsoft.Template/uri/' + deployToAzureUrl; let query = ''; let uri = vscode.Uri.from({ scheme, authority, path, query, fragment }); void vscode.env.openExternal(uri); }

I think the problem is because I am using encodeURIComponent method

Is there any other method that can be used to open a URL ? Preferably where I can pass the URL as a string and the function just opens without doing any modification in URL

jrieken commented 1 month ago

I think the problem is because I am using encodeURIComponent method

Try without that?

sahuroshan commented 1 month ago

@jrieken
I can't skip encodeURIComponent. I need to encode some part of URl.

sahuroshan commented 1 month ago

@jrieken is there any API available or any other method that can be used?

oeyoews commented 2 weeks ago

I had the same problem. Both vscode.env.openExternal(Uri.parse(link)) and follow link were invalid. Did anyone notice this? I downgraded VScode to 1.94.2 and everything worked fine.

Image

oeyoews commented 2 weeks ago

I had the same problem. Both vscode.env.openExternal(Uri.parse(link)) and follow link were invalid. Did anyone notice this? I downgraded VScode to 1.94.2 and everything worked fine.

Image

If clicking doesn't work, you can try restarting your computer to fix this problem. This is very strange.