Adding objects to Web Worker context



  • I'm starting a Web Worker from inside a page which is loaded in a QWebView. While loading, I use the "javaScriptWindowObjectCleared" signal to add custom objects to the frame (using "addToJavaScriptWindowObject"). This works fine for the page initially loaded, but these objects are not available in the Web Worker context and there seems to be no signal that is triggered when the Worker starts.

    Is there a way to get notified about new Web Workers so I can add my objects?



  • You did not understand how Web Workers work. They have their own context and can never access the DOM or a window object -- well, some say that Web Workers exist in a vacuum. See here:

    "http://www.html5rocks.com/en/tutorials/workers/basics/#toc-enviornment-features":http://www.html5rocks.com/en/tutorials/workers/basics/#toc-enviornment-features

    That behaviour has nothing to do with QtWebKit but is the normal Web Worker specification. An object you add with @addToJavaScriptWindowObject("THIS_GETS_TO_THE_DOM", yourObject)@

    is added to the DOM (where else should it be placed?)! So, no chance that you can access it from within your Web Worker.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.