browserstack / browserstack-local-nodejs

NodeJS bindings for BrowserStack Local
https://www.browserstack.com
MIT License
71 stars 56 forks source link

Network logging restricts websockets usage #106

Open dimkin-eu opened 4 years ago

dimkin-eu commented 4 years ago

if AUT is using ws for communication - it fails when running on Browserstack, because fails to connect update - see the workaround in the end

Environment (please complete the following information):

To reproduce

  1. save files in one folder
  2. add env vars BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY
  3. run npm install and then npm test package.json bsSpec.js wdio.conf.js

Same happens, if BrowserstackLocal started as background service ./BrowserStackLocal --key somekey

Expected behavior test runs

Actual behavior

using localtesing ws connect fails

1591701360194:SEVERE:https://www.websocket.org/js/echo.js 135 WebSocket connection to 'wss://echo.websocket.org/?encoding=text' failed: Error during WebSocket handshake: Unexpected response code: 400
Screenshot 2020-06-09 at 14 35 16

Workaround As turned out - network logging "turns off" ws communication

dimkin-eu commented 4 years ago

@shawnlobo96 maybe you can help with this issue? :)

anthony-fdes commented 4 years ago

@dimkin-eu Can you execute the tests without Network Logs? Also, BrowserStack only supports secure Web Sockets so could you please confirm if you are using secure Web Sockets only?

dimkin-eu commented 4 years ago

@anthony-fdes , under secure WebSockets you mean wss://? then yes - they are used And yes, turning off network logs made ws working. This is quite nasty and not obvious :( Can this be fixed or at least mentioned on https://www.browserstack.com/local-testing/automate ?

Thank you for fast heads-up :)

shawnlobo96 commented 4 years ago

Hey @dimkin-eu,

You can try adding the below capability:

'browserstack.wsLocalSupport': 'true'

This has been documented under https://www.browserstack.com/automate/capabilities. This should allow WebSocket connections with network logs enabled. The reason for using this capability is mentioned as:

Chrome browser v71 and above have changed the way PAC files are supported. 
Use this capability to enable WSS (WebSocket Secure) connections to work with Network Logs on Chrome browser v71 and above.

If you are using localhost in your test, change it to bs-local.com

Note: This capability is only valid for Chrome browsers v71 and above.

I hope you find this useful :)

dimkin-eu commented 4 years ago

@shawnlobo96 , nice, will check :)

This needs some more things, if one testing locally and in Browserstack, will check this too