diff --git a/devtool/devtool.go b/devtool/devtool.go index 0d21a64..06fc833 100644 --- a/devtool/devtool.go +++ b/devtool/devtool.go @@ -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. diff --git a/devtool/headless_test.go b/devtool/headless_test.go index e12f714..bbd2326 100644 --- a/devtool/headless_test.go +++ b/devtool/headless_test.go @@ -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" }`)}, @@ -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"