Giter Club home page Giter Club logo

Comments (10)

kenshaw avatar kenshaw commented on May 18, 2024

You can try this with the chromedp project:

$ cd $GOPATH/src && mkdir -p github.com/chromedp && cd github.com/chromedp
$ git clone -b test-websocket-impls https://github.com/kenshaw/chromedp.git
$ cd $GOPATH/src/github.com/chromedp/chromedp
$ go test -v -tags gorilla
$ go test -v -tags gobwas
$ go test -v -tags nhooyr

from websocket.

nhooyr avatar nhooyr commented on May 18, 2024

Thank you for the detailed report.

You seem to be using the package fine. Will fix the redundant and verbose errors in #47

I'm looking into this.

from websocket.

nhooyr avatar nhooyr commented on May 18, 2024

So I've gotten to the bottom of this. It looks like a bug in chrome's dp tooling to me.

It cannot handle continuation frames. With gorilla/websocket and gobwas/ws, you're sending a single text frame but with this library, first the text frame is sent, then a continuation frame that finishes the frame. This is just due to the streaming style API, it doesn't know when to finish the message until you call w.Close.

from websocket.

nhooyr avatar nhooyr commented on May 18, 2024

see

websocket/websocket_test.go

Lines 461 to 494 in d50ecee

func TestChrome(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
c, _, err := websocket.Dial(ctx, "ws://127.0.0.1:56213/devtools/browser/f6427288-77aa-49d6-983f-a4afe482d5b6")
if err != nil {
t.Fatal(err)
}
defer c.Close(websocket.StatusInternalError, "")
// write initial message
err = c.WriteFrame(ctx, websocket.MessageText, []byte(`{"id":1,"method":"Target.getTargets","params":{}}`))
if err != nil {
t.Fatal(err)
}
log.Printf("wrote Target.getTargets message")
// read response
jc := websocket.JSONConn{
Conn: c,
}
var v interface{}
err = jc.Read(ctx, &v)
if err != nil {
log.Fatalf("failed to read json: %v", err)
}
buf, err := json.Marshal(v)
if err != nil {
t.Fatal(err)
}
log.Printf("received %s", string(buf))
c.Close(websocket.StatusNormalClosure, "")
}

I added a c.WriteFrame method to confirm this and now the code works. If you try and use the streaming API, it fails.

This is very surprising to me so I could be wrong, I'll check chrome's code.

from websocket.

nhooyr avatar nhooyr commented on May 18, 2024

Known issue ChromeDevTools/devtools-protocol#24

from websocket.

nhooyr avatar nhooyr commented on May 18, 2024

Filed a bug at https://bugs.chromium.org/p/chromium/issues/detail?id=954778

Thanks again for the report @kenshaw

from websocket.

nhooyr avatar nhooyr commented on May 18, 2024

Going to close this as it's not a bug in this library and I do not want to expose a function because of a bug in chrome. I'll keep that branch for now in case you want to use it.

from websocket.

kenshaw avatar kenshaw commented on May 18, 2024

While the Chrome Websocket implementation may not support this, it would be prudent for this package to do so, as the other websocket implementations available do. I agree it's not a bug in this package, but if you'd like greater adoption of this package, then it needs to support existing software in the wild. I imagine other websocket implementations also have this issue.

from websocket.

nhooyr avatar nhooyr commented on May 18, 2024

You make a solid point. Given I already have the code for this, I think its ok to expose a method that performs a write of a byte slice directly instead of returning a writecloser.

from websocket.

nhooyr avatar nhooyr commented on May 18, 2024

See #62

from websocket.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.