HTML5: shared web worker with multiple connections


From what I understand, the big benefit of HTML5's shared web workers is that they can accept multiple connections in a single separate thread of execution.

My question is: has anyone gotten multiple connections with a SharedWorker to work as a single thread with Google Chrome? I'm using latest version 12.0.742.112.

Demo: <a href="http://demos.zulius.com/html5/sharedworker" rel="nofollow">http://demos.zulius.com/html5/sharedworker</a>

Source (in case demo is down): <a href="http://pastebin.com/N5uAsLVR" rel="nofollow">index.html</a>, <a href="http://pastebin.com/DfEux7aP" rel="nofollow">sharedworker.js</a>

The demo establishes 2 separate event listeners. The expected output is:

foo got message: Hello World! You are connection #1 bar got message: Hello World! You are connection #2

In the demo, both event listeners fire correctly, but the connection count variable is not maintained in the SharedWorker script. This leads me to believe each connection to the SharedWorker is executing in a separate thread.

Am I doing something wrong? Or is Chrome support for SharedWorker not quite there?

<strong>UPDATE:</strong> the demo works now.


You have 2 listeners to the Worker but you only start the Worker for once, so it's 1 Worker shared by 1 owner instead of 2 owners. Increasing the number of listeners doesn't affect the ownership.

You can see the example here: <a href="http://weblog.bocoup.com/javascript-web-workers-chrome-5-supports-new-sharedworker" rel="nofollow">http://weblog.bocoup.com/javascript-web-workers-chrome-5-supports-new-sharedworker</a>

It has 2 frames, one containing the iframe and one inside the iframe. They both call the start method of the Worker so it's shared by 2 owners. Since the start method is called twice, the onconnect event should be fired twice, thus making connection.count equal 2.


In shared webworkers the context is alive till the last browser session end. shared webworkers can maintain the context around the browser tabs. They respond to the requests with the same context of data.

The change in context of data will affect all connections, the possibilities are you can update all the connections with single context change, you can maintain the data till the last connection end. you can maintain the connection changes in all views.

Here is a demo of Shared web workers with multiple connections.

<a href="http://www.antkorp.in/sharedworkers/" rel="nofollow">http://www.antkorp.in/sharedworkers/</a>


  • How arguments are passed into a cppFunction
  • Are Shared WebWorkers supported in IE 11?
  • React Native Navigation Gesture
  • React Native - debugging exception
  • Does JavaScript run out of timeout IDs?
  • three.js - geometry.faceVertexUvs[0][0][index] is not the same as geometry.vertices[index]
  • The schema returned by query is differ from base query
  • Evaluating FeatherJS Authentication Needs
  • iphone/ipad web video only plays over 3g not Wifi
  • Paging toolbar on custom component querying local data store
  • ng-model for `` (with directive DEMO)
  • How to search a string in inner array using mongodb?
  • React JS 'this' not working as expected
  • Is there any way to center certain columns in table?
  • Git Configuration with eclipse--not able to push code from eclipse to remote git server
  • regex question for removal of javascript malware
  • Graph matplotlib to show total count in the histogram bins
  • Best Practice for Cell Editing (Single-Click or Double-Click) in Table in Swing
  • Raise Session_OnStart event from custom ASP.NET SessionStateProvider class
  • Using Delphi + Jedi, losing USB data when device sends it “too fast”
  • Add Jpanel to Jframe NetBeans
  • How to convert Neo4j Result to GraphJSON
  • Recursion in ASP.NET Core Razor views
  • Positioning children objects in scene (car wheels hierarchy)
  • How to read JSON-LD data from HTML in Objective-C?
  • Need a consistent TimePicker gizmo for mobile web site
  • Ionic Slide Up Slide Down Animation for only one view in sidebar
  • Angular Bootstrap Carousel Slide Transition not working correctly
  • d3 v4 drag and drop with TypeScript
  • JQuery Internet Explorer and ajaxstop
  • Meteor helpers not available in Angular template
  • PHPUnit_Framework_TestCase class is not available. Fix… - Makegood , Eclipse
  • Opengl-es onTouchEvents problem or a draw problem? [closed]
  • Rearranging Cells in UITableView Bug & Saving Changes
  • How to get icons for entities from eclipse?
  • Proper way to use connect-multiparty with express.js?
  • Load html files in TinyMce
  • Linking SubReports Without LinkChild/LinkMaster
  • JaxB to read class hierarchy
  • Conditional In-Line CSS for IE and Others?