Experiencing error with Pass User Agent Info to Your LiveView article - (ArgumentError) expected a keyword list as the second argument

I am looking to implement passing the user agent to liveview based on this article https://fly.io/phoenix-files/pass-user-agent-info-to-your-liveview/

The suggested change is

- socket "/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]]
+ socket "/live", Phoenix.LiveView.Socket, websocket: [:user_agent, connect_info: [session: @session_options]]

I end up with the following error using Phoenix 1.7.0 and Elixir 1.14.3

== Compilation error in file lib/my_app_web/endpoint.ex ==
** (ArgumentError) expected a keyword list as the second argument, got: [:user_agent, {:connect_info, [session: [store: :cookie, key: "_my_app_key", signing_salt: "S+qhbMV3"]]}]
    (elixir 1.14.3) lib/keyword.ex:995: Keyword.merge/2
    (phoenix 1.7.0) lib/phoenix/socket/transport.ex:235: Phoenix.Socket.Transport.load_config/2
    (phoenix 1.7.0) lib/phoenix/endpoint.ex:650: Phoenix.Endpoint.socket_paths/4
    (phoenix 1.7.0) lib/phoenix/endpoint.ex:604: anonymous fn/3 in Phoenix.Endpoint."MACRO-__before_compile__"/2
    (elixir 1.14.3) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
    (phoenix 1.7.0) expanding macro: Phoenix.Endpoint.__before_compile__/1
    lib/my_app_web/endpoint.ex:1: PetalProWeb.Endpoint (module)

Any help is appreciated.

The post has a typo. The :user_agent atom should be within the :connect_info config, not outside of it.

socket "/live", Phoenix.LiveView.Socket, websocket: [connect_info: [:user_agent, session: @session_options]]

Thank you, @mcrumm ! that was it.

1 Like