Using cookies with WEBSOCKET_XHR

I tried using the following example to read and write cookies in my application: https://vaadin.com/wiki/-/wiki/Main/Setting+and+reading+Cookies

I am using websockets, so I updated my transport type to WEBSOCKET_XHR, yet VaadinService.getCurrentResponse() always returns null for me. Is there a different example specific to WEBSOCKET_XHR, or something else I’m missing here?

Using javascript to write the cookie makes it functional, I can read cookies fine with the example code found in the wiki. This works for me, but I feel like the wiki may need to be updated in some way, as it is does not seem to work still with websocket_xhr.

Page.getCurrent().getJavaScript().execute(String.format("document.cookie = '%s=%s;';", "user", username));

I am getting the same problem. I can’t find any easy way to set cookies with WEBSOCKET_XHR.

If anyone finds out how to do it, please share :slight_smile:

Hi, when using

Page.getCurrent().getJavaScript().execute(String.format(“document.cookie = ‘%s=%s;’;”, cookie.getName(), cookie.getValue()));

I have problems if the cookie value contains a @

Should I encode special chars?