Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

binary websocket support #370

Closed
paulirish opened this issue Sep 8, 2011 · 7 comments
Closed

binary websocket support #370

paulirish opened this issue Sep 8, 2011 · 7 comments

Comments

@paulirish
Copy link
Member

window.WebSocket && (new WebSocket('ws://.')).binaryType

is the basic test.. truthy (returns "blob") if there is support.. as there is in new chrome canary.

https://plus.google.com/115535723976198353696/posts/ERN6zYozENV

@sirbarrence
Copy link

In Modernizr 2.6.2, IE 10.0.9200.16438 on Win7

(new WebSocket('ws://.')).binaryType

throws

"Unspecified error."

so the test evals to false.

But if you supply a valid host instead of "."

(new WebSocket('ws://0.0.0.0')).binaryType

you get a truthy

"blob"

which causes the test eval to true. Of course you might later get some unsightly error on the console if the WebSocket doesn't get a response it expects. So I'm not really sure what should be used to test this if IE doesn't like ".".

@ryanseddon
Copy link
Member

Also interesting to note if this is ran on an https page it will throw a security error in IE10 and Firefox but not Chrome.

blob-ws

@ryanseddon
Copy link
Member

Ok so here's a potential solution that returns expected results. It looks like everyone but Chrome exposes binaryType on the WebSocket.prototype and since Chrome passes the original check no problems that's fine. But Opera doesn't expose binaryType and it will crack it if it's ran on a secure page. So I do a check for the protocol to switch between ws and wss. I do the in check first as that'll be cheaper and less error prone.

Modernizr.addTest('websocketsbinary', function() {
  var protocol = 'https:'==location.protocol?'wss':'ws',
      protoBin = "binaryType" in WebSocket.prototype;

  if("WebSocket" in window) {
      if( protoBin ) return protoBin;
      try {
          return !!(new WebSocket(protocol+'://.').binaryType);
      } catch (e){}
    }

    return false;
});

@sirbarrence can you try this test case and see if that returns expected results for you? http://codepen.io/ryanseddon/pen/Ggydu

@ryanseddon
Copy link
Member

Actually i'll need to put that protoBin variable inside the if as non WebSocket browsers will throw. Updated test case.

@sirbarrence
Copy link

Yeah, seems ok. IE 8 & 9 are false and IE 10 is true as expected. Chrome 24 (Mac) and Firefox 18 (Mac) are true as expected.

@ryanseddon ryanseddon reopened this Jan 31, 2013
SlexAxton pushed a commit to SlexAxton/Modernizr that referenced this issue Feb 14, 2013
SlexAxton added a commit to SlexAxton/Modernizr that referenced this issue Feb 23, 2013
* 'master' of github.com:Modernizr/Modernizr: (70 commits)
  Fixed a typo in `testMediaQuery()`
  Added wrapflow test, in AMD format - fixes Modernizr#786
  Fixes missing brackets and removes unneeded "Pre 1.2" from the user agent regex ("webOS" already covers that).
  Corrected name for `touch` (to `touchevents`) in Modernizr-caniuse mapping
  Robustisize the binary WebSocket detect. Fixes Modernizr#370
  Update detect for fullscreen api. Fixes Modernizr#739
  Added DOM PointerEvents test as Modernizr.pointerevents
  Moved Modernizr.pointerevents -> Modernizr.csspointer events (API break...)
  Moved Modernizr.touch -> Modernizr.touchevents (kept an alias though)
  Matches Modernizr#777 in v3 land.
  Matches Modernizr#774 in v3 land.
  Matches Modernizr#773 in v3 land.
  whitespace
  Adds 'peerconnection' feature detection, namespaces WebRTC features together
  Tweaked csstransforms3d style test numbers to work around rounding bug in Chrome 23.0 when zoomed (Modernizr#760)
  Added fileinput test mobile UA blacklist for issue Modernizr#772
  Added fileinput test mobile UA blacklist for issue Modernizr#772
  adding docs from alex's email.
  whitespace
  SUPERSECRET MICROSOFT REQUESTED SENSORSHIP
  ...
SlexAxton added a commit to SlexAxton/Modernizr that referenced this issue Feb 23, 2013
* 3pre: (58 commits)
  fill up metadata a bit more, a few new conventions
  Saving full dependecies into package.json
  Removing node_modules, adding in metadata reader, ignoring generated metadata
  remove the node modules via an ignore
  Corrected name for `touch` (to `touchevents`) in Modernizr-caniuse mapping
  Robustisize the binary WebSocket detect. Fixes Modernizr#370
  Update detect for fullscreen api. Fixes Modernizr#739
  Added DOM PointerEvents test as Modernizr.pointerevents
  Moved Modernizr.pointerevents -> Modernizr.csspointer events (API break...)
  Moved Modernizr.touch -> Modernizr.touchevents (kept an alias though)
  Matches Modernizr#777 in v3 land.
  Matches Modernizr#774 in v3 land.
  Matches Modernizr#773 in v3 land.
  whitespace
  Adds 'peerconnection' feature detection, namespaces WebRTC features together
  Tweaked csstransforms3d style test numbers to work around rounding bug in Chrome 23.0 when zoomed (Modernizr#760)
  Added fileinput test mobile UA blacklist for issue Modernizr#772
  Added fileinput test mobile UA blacklist for issue Modernizr#772
  adding docs from alex's email.
  whitespace
  ...

Conflicts:
	config-all.json
	feature-detects/css/animations.js
	feature-detects/forms/fileinput.js
	modular.html
	package.json
@lotodore
Copy link

Thanks for the fix - however, obviously this did not find its way into a stable release. This is still broken in 2.7.1. Could someone tell me please why this is not fixed in public release? If I generate code using
http://modernizr.com/download/#-websockets_binary
it is still broken.

@patrickkettner
Copy link
Member

This was released in v2.8.0

patrickkettner pushed a commit to patrickkettner/Modernizr that referenced this issue Feb 22, 2015
patrickkettner pushed a commit to patrickkettner/Modernizr that referenced this issue Feb 22, 2015
patrickkettner pushed a commit to patrickkettner/Modernizr that referenced this issue Feb 22, 2015
patrickkettner pushed a commit to patrickkettner/Modernizr that referenced this issue Feb 22, 2015
* 'master' of github.com:Modernizr/Modernizr: (70 commits)
  Fixed a typo in `testMediaQuery()`
  Added wrapflow test, in AMD format - fixes Modernizr#786
  Fixes missing brackets and removes unneeded "Pre 1.2" from the user agent regex ("webOS" already covers that).
  Corrected name for `touch` (to `touchevents`) in Modernizr-caniuse mapping
  Robustisize the binary WebSocket detect. Fixes Modernizr#370
  Update detect for fullscreen api. Fixes Modernizr#739
  Added DOM PointerEvents test as Modernizr.pointerevents
  Moved Modernizr.pointerevents -> Modernizr.csspointer events (API break...)
  Moved Modernizr.touch -> Modernizr.touchevents (kept an alias though)
  Matches Modernizr#777 in v3 land.
  Matches Modernizr#774 in v3 land.
  Matches Modernizr#773 in v3 land.
  whitespace
  Adds 'peerconnection' feature detection, namespaces WebRTC features together
  Tweaked csstransforms3d style test numbers to work around rounding bug in Chrome 23.0 when zoomed (Modernizr#760)
  Added fileinput test mobile UA blacklist for issue Modernizr#772
  Added fileinput test mobile UA blacklist for issue Modernizr#772
  adding docs from alex's email.
  whitespace
  SUPERSECRET MICROSOFT REQUESTED SENSORSHIP
  ...
patrickkettner pushed a commit to patrickkettner/Modernizr that referenced this issue Feb 22, 2015
* 3pre: (58 commits)
  fill up metadata a bit more, a few new conventions
  Saving full dependecies into package.json
  Removing node_modules, adding in metadata reader, ignoring generated metadata
  remove the node modules via an ignore
  Corrected name for `touch` (to `touchevents`) in Modernizr-caniuse mapping
  Robustisize the binary WebSocket detect. Fixes Modernizr#370
  Update detect for fullscreen api. Fixes Modernizr#739
  Added DOM PointerEvents test as Modernizr.pointerevents
  Moved Modernizr.pointerevents -> Modernizr.csspointer events (API break...)
  Moved Modernizr.touch -> Modernizr.touchevents (kept an alias though)
  Matches Modernizr#777 in v3 land.
  Matches Modernizr#774 in v3 land.
  Matches Modernizr#773 in v3 land.
  whitespace
  Adds 'peerconnection' feature detection, namespaces WebRTC features together
  Tweaked csstransforms3d style test numbers to work around rounding bug in Chrome 23.0 when zoomed (Modernizr#760)
  Added fileinput test mobile UA blacklist for issue Modernizr#772
  Added fileinput test mobile UA blacklist for issue Modernizr#772
  adding docs from alex's email.
  whitespace
  ...

Conflicts:
	config-all.json
	feature-detects/css/animations.js
	feature-detects/forms/fileinput.js
	modular.html
	package.json
openstack-gerrit pushed a commit to openstack-archive/deb-novnc that referenced this issue Sep 16, 2016
A facke connection to 'wss://localhost:17523' (randomly chosen) to detect
the WebSocket binary support is not the best solution.
First of all, check of prototype has the property 'binaryType'. If not,
perform a dummy connection to 'wss://.' instead of 'wss://localhost:17523'.

This patch was inspired by the discussion and implementation of Modernizr:
Modernizr/Modernizr#370
https://github.com/Modernizr/Modernizr/blob/master/feature-detects/websockets/binary.js
chinnkarahoi pushed a commit to chinnkarahoi/noVNC that referenced this issue Jan 27, 2023
A facke connection to 'wss://localhost:17523' (randomly chosen) to detect
the WebSocket binary support is not the best solution.
First of all, check of prototype has the property 'binaryType'. If not,
perform a dummy connection to 'wss://.' instead of 'wss://localhost:17523'.

This patch was inspired by the discussion and implementation of Modernizr:
Modernizr/Modernizr#370
https://github.com/Modernizr/Modernizr/blob/master/feature-detects/websockets/binary.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants