Repository: microsoft/vscode-edge-devtools (ts)

Issue:
Extension fails to relaunch an instance (headless)
<!-- ⚠️⚠️ Do Not Delete This! These are comments and will not show up in Preview ⚠️⚠️ -->
<!-- Please read our Rules of Conduct: https://opensource.microsoft.com/codeofconduct/ -->
<!-- Please search existing issues to avoid creating duplicates. -->

**Environment (please complete the following information):**
 - OS (*e.g.,* Windows 10): Windows 11 
 - Extension version (*e.g.,* 1.2.3): 2.1.3
<!-- The extension version can be found by hovering or selecting "Microsoft Edge Tools for VS Code" in the VS Code Extensions Marketplace panel. -->

**Describe the bug:**
<!-- A clear and concise description of what the bug is -->
Extension fails to launch an instance after I already have launched and close a previous one.
**Repro steps:**
1. Open extension
2. Turn on `Vscode-edge-devtools:headless` on the extension settings.
3. Click on launch Instance
4. extension should launch
5. Close the instance (either by clicking on the close button or on the 'x' next to the instance name)
6. Click on launch Instance again

<!-- Steps to reproduce the behavior. -->

**Expected behavior:**
Devtools should launch
<!-- A clear and concise description of what you expected to happen. -->

**Actual behavior:**
Error while fetching list of available targets No available targets to attach.
<!-- Add any other context or about the problem or screenshots here. -->


Pull request:
Fixing relaunch scenario on headless
Extension was failing to relaunch on headless. This was due to the host responding with `Using unsafe HTTP verb GET to invoke /json/new. Recommended way is to use PUT`. This PR fixes the issue and adds a test to avoid regression.

Fix #1978 

Patch:
diff --git a/src/utils.ts b/src/utils.ts
index d43035a..933db45 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -158,6 +158,7 @@ export function fetchUri(uri: string, options: https.RequestOptions = {}): Promi
             rejectUnauthorized: false,
             ...parsedUrl,
             ...options,
+            method: 'PUT',
         } as http.RequestOptions;
 
         get(options, response => {


Test patch:
diff --git a/test/utils.test.ts b/test/utils.test.ts
index 530bc4f..522ac0f 100644
--- a/test/utils.test.ts
+++ b/test/utils.test.ts
@@ -79,6 +79,25 @@ describe("utils", () => {
             expect(fake.on).toHaveBeenNthCalledWith(2, "end", expect.any(Function));
         });
 
+        it("options passed to 'get' uses PUT as HTTP verb", async () => {
+            // Chrome headless require 'PUT' instead of 'GET' for /json/new otherwise we get
+            // 'Using unsafe HTTP verb GET to invoke /json/new. The recommended way is to use PUT'
+            const httpGetMock = mockGetHttp;
+            const customError = new Error('customError');
+            const fakeGet = (_options: any, callback: (resp: object) => void) => {
+                expect(_options.method).not.toBeUndefined();
+                expect(_options.method).toEqual('PUT');
+
+                // after validation we can halt execution to resolve the promise chain.
+                return { on: () => { throw customError } }
+            };
+
+            httpGetMock.mockImplementation(fakeGet);
+            await utils.fetchUri("http://somedomain.com/json/list").catch((error: any) => {
+                expect(error).toEqual(customError);
+            })
+        });
+
         it("requests http url correctly", async () => {
             const expectedHttpResponse = "[{},{}]";
             mockGetHttp.mockImplementation(