Repository: aerokube/selenoid
Pull request #1361 (2023-07-13 08:57:16)

fix: correctly parse sessionId for chrome less 75
In the process of implementing #1354, I broke work with the chrome browser version below 75. Response body from chrome@67 looks like this:
```
{
    sessionId: "session_id",
    status: 0,
    value: {
        browserName: "chrome",
        // ... (without "capabilities" field)
    }
}
```

In chrome 75 and older looks like this:
```
{
    value: {
        capabilities: {
            browserName: "chrome",
            // ...
        },
        sessionId: "session_id"
    }
}
```

It means that `sessionId` can be located in different places depending on browser version.

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/aerokube/selenoid/pull/1361?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aerokube) Report
Patch coverage: **`57.50`**% and project coverage change: **`-0.52`** :warning:
> Comparison is base [(`33d6893`)](https://app.codecov.io/gh/aerokube/selenoid/commit/33d68939acba3f4ed4c5a90c7d1d654440400a3b?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aerokube) 74.44% compared to head [(`8615bbf`)](https://app.codecov.io/gh/aerokube/selenoid/pull/1361?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aerokube) 73.92%.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #1361      +/-   ##
==========================================
- Coverage   74.44%   73.92%   -0.52%     
==========================================
  Files          12       12              
  Lines        1831     1845      +14     
==========================================
+ Hits         1363     1364       +1     
- Misses        383      394      +11     
- Partials       85       87       +2     
```

| Flag | Coverage Δ | |
|---|---|---|
| go | `73.92% <57.50%> (-0.52%)` | :arrow_down: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aerokube#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://app.codecov.io/gh/aerokube/selenoid/pull/1361?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aerokube) | Coverage Δ | |
|---|---|---|
| [selenoid.go](https://app.codecov.io/gh/aerokube/selenoid/pull/1361?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aerokube#diff-c2VsZW5vaWQuZ28=) | `82.75% <57.50%> (-1.70%)` | :arrow_down: |


</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/aerokube/selenoid/pull/1361?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aerokube).   
:loudspeaker: Do you have feedback about the report comment? [Let us know in this issue](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aerokube).


Patch:
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 17b72f4..82efff9 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -14,7 +14,7 @@ jobs:
       - name: Setup Golang
         uses: actions/setup-go@v3
         with:
-          go-version: ~1.20.4
+          go-version: ~1.20.6
 
       - uses: actions/cache@v3
         with:
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 29a7f01..9ed19d3 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -13,7 +13,7 @@ jobs:
       - name: Setup Golang
         uses: actions/setup-go@v3
         with:
-          go-version: ~1.20.4
+          go-version: ~1.20.6
 
       - uses: actions/cache@v3
         with:
diff --git a/selenoid.go b/selenoid.go
index 1f9a2ee..1987d38 100644
--- a/selenoid.go
+++ b/selenoid.go
@@ -413,12 +413,19 @@ func processBody(input []byte, host string) ([]byte, string, error) {
 	if err != nil {
 		return nil, sessionId, fmt.Errorf("parse body response: %v", err)
 	}
-	if raw, ok := body["value"]; ok {
-		if v, ok := raw.(map[string]interface{}); ok {
-			if raw, ok := v["capabilities"]; ok {
-				if c, ok := raw.(map[string]interface{}); ok {
-					sessionId = v["sessionId"].(string)
-					c["se:cdp"] = fmt.Sprintf("ws://%s/devtools/%s/", host, sessionId)
+	// handle jsonwp response from older browsers (chrome < 75)
+	if rawId, ok := body["sessionId"]; ok {
+		if si, ok := rawId.(string); ok {
+			sessionId = si
+		}
+	} else {
+		if raw, ok := body["value"]; ok {
+			if v, ok := raw.(map[string]interface{}); ok {
+				if raw, ok := v["capabilities"]; ok {
+					if c, ok := raw.(map[string]interface{}); ok {
+						sessionId = v["sessionId"].(string)
+						c["se:cdp"] = fmt.Sprintf("ws://%s/devtools/%s/", host, sessionId)
+					}
 				}
 			}
 		}


Test patch:
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 545ad8d..073b451 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -12,7 +12,7 @@ jobs:
       - name: Setup Golang
         uses: actions/setup-go@v3
         with:
-          go-version: ~1.20.4
+          go-version: ~1.20.6
 
       - uses: actions/cache@v3
         with: