Skip to content

Commit

Permalink
devtool: Fix usage with Node.js debugger (#142)
Browse files Browse the repository at this point in the history
Fixes #141
  • Loading branch information
mafredri committed Apr 4, 2023
1 parent 0a8c15b commit bff3544
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion devtool/devtool.go
Expand Up @@ -247,7 +247,11 @@ func (d *DevTools) httpPut(ctx context.Context, path string) (*http.Response, er

resp, err := d.client.Do(req.WithContext(ctx))
if err == nil {
return resp, nil
// Node.js returns status 400 for PUT requests.
if resp.StatusCode < 400 {
return resp, nil
}
resp.Body.Close()
}

// Fallback to old method, use GET request.
Expand Down
2 changes: 2 additions & 0 deletions devtool/headless_test.go
Expand Up @@ -67,6 +67,7 @@ func TestDevTools_HeadlessCreateURL(t *testing.T) {
h: []http.Handler{
&testHandler{hostnameLookup: true},
&testHandler{status: 500},
&testHandler{status: 500}, // Two tries because of Node fallback.
&testHandler{status: 200, body: []byte(`{
"Browser": "HeadlessChrome/60.0.3578.30"
}`)},
Expand Down Expand Up @@ -98,6 +99,7 @@ func TestDevTools_HeadlessCreateURLFail(t *testing.T) {
t: t,
h: []http.Handler{
&testHandler{status: 500},
&testHandler{status: 500}, // Two tries because of Node fallback.
&testHandler{status: 200, body: []byte(`{
"Browser": "HeadlessChrome/71.0.3578.30",
"webSocketDebuggerUrl": "ws://localhost:9222/devtools/browser/14731399-e013-4802-a8b6-500b3870288e"
Expand Down

0 comments on commit bff3544

Please sign in to comment.