Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-64408

Support multiple instances of QWebChannel in the same page

    XMLWordPrintable

Details

    • 441fc2ad9 (dev), 621eb695c (6.7), f8b153a22 (tqtc/lts-6.5)

    Description

      At the moment the QWebChannel JavaScript type makes a few assumptions that make it impossible to create two instances of this object in the context of the same page. In particular each instance has its own message-id counter, so both instances will end up using the same message id's for possibly different messages. In addition the second instances breaks the onmessage handler of the first instance because it overrides that function on the transport.

      The use-case I'm looking at which needs two instances of QWebChannel on the JS side is instrumentation of the page running inside a WebEngineView by froglogic Squish. Squish is using a QObject registered with the page's QWebChannel instance for communication purposes between JS code and C++ code. That way Squish can  leverage the Chrome IPC transport thats available in WebEngineView. In order to stay as non-intrusive as possible it uses its own QWebChannel instance for this, but as explained above this breaks a QWebChannel instance used by the application itself. Access to the applications QWebChannel instance is not feasible as this would require the application to know about the instrumentation by Squish and require a guarantee that the injection through Squish happens at a defined point before or after the applications QWebChannel has been setup.

      The attached example demonstrates the issue, its a slightly modified version of the markdowneditor. It creates two QWebChannel instances in JS and has the qwebchannel.js modified to log which instance sees which messages.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            milianw Milian Wolff
            andreaspakulat Andreas Pakulat
            Votes:
            1 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes