code: func Dial(url string) (net.Conn, error) {
  	ws, err := websocketjs.New(url)
  	if err != nil {
  		return nil, err
  	}
  	conn := &conn{
  		WebSocket: ws,
  		ch:        make(chan *messageEvent, 1),
  	}
  	conn.initialize()
  
  	openCh := make(chan error, 1)
  
  	var (
  		openHandler  func(ev *js.Object)
  		closeHandler func(ev *js.Object)
  	)
  
  	// Handlers need to be removed to prevent a panic when the WebSocket closes
  	// immediately and fires both open and close before they can be removed.
  	// This way, handlers are removed before the channel is closed.
  	removeHandlers := func() {
  		ws.RemoveEventListener("open", false, openHandler)
  		ws.RemoveEventListener("close", false, closeHandler)
  	}
  
  	// We have to use variables for the functions so that we can remove the
  	// event handlers afterwards.
  	openHandler = beginHandlerOpen(openCh, removeHandlers)
  	closeHandler = beginHandlerClose(openCh, removeHandlers)
  
  	ws.AddEventListener("open", false, openHandler)
  	ws.AddEventListener("close", false, closeHandler)
  
  	err, ok := <-openCh
  	if ok && err != nil {
  		return nil, err
  	}
  
  	return conn, nil
  }
docs: // TODO(nightexcessive): Add a Dial function that allows a deadline to be
  // specified.
  // Dial opens a new WebSocket connection. It will block until the connection is
  // established or fails to connect.