Links does not open in QWebView



  • I'm trying to integrate 3rd party web-service into my program. For this I use QWebView which opens a page with some JS code. Page loads fine, but when I click on any link nothing happens and there is no indication what is wrong.

    Here is test code

    import os
    import sys
    
    from PyQt5.QtCore import QUrl
    from PyQt5.QtWidgets import QApplication
    from PyQt5.QtWebKit import QWebSettings
    from PyQt5.QtWebKitWidgets import QWebView, QWebInspector, QWebPage
    
    app = QApplication(sys.argv)
    webView = QWebView()
    QWebSettings.globalSettings().setAttribute(QWebSettings.PluginsEnabled, True)
    QWebSettings.globalSettings().setAttribute(QWebSettings.LocalContentCanAccessRemoteUrls, True)
    webView.page().settings().setAttribute(QWebSettings.DeveloperExtrasEnabled, True)
    inspector = QWebInspector()
    inspector.setPage(webView.page())
    
    content = ''
    with open(os.path.join(os.path.dirname(__file__), 'index.html'), 'rb') as f:
        content = f.read()
    
    webView.setContent(content)
    webView.show()
    app.exec_()
    

    And here is HTML I'm using

    <html>
      <head>
        <script type="text/javascript" src="https://cdn.3dmapping.cloud/18.1.4/javascript/orbitgt_3dm_sdk.js"></script>
      </head>
    
      <body >
        <div id="app">
    
        <script type="text/javascript">
          var viewer;
    
          function handleReady() {
            viewer.setSize(600,400);
          }
    
          function handleDOMReady() {
            var applicationName = "test app";
            var appElement = document.getElementById("m3dviewer");
            viewer = new orbitgt.mapping3d.sdk.viewer.SDKViewer(applicationName, appElement);
            viewer.isReady.then(handleReady);
          }
    
          document.addEventListener("DOMContentLoaded", handleDOMReady);
        </script>
    
        <div id="m3dviewer"/>
      </body>
    </html>
    

    I'm on Linux, Qt version is 5.9.5 and Python 3.6.5



  • Hmm, seems this is because QtWebkit lacks support of some JS features (not fully compliant with ECMA?). Can anyone confirm?

    Maybe there are some workarounds or list of unsupported JS features?



  • You need to use QtWebKit 5.212 to get more supported JS features



  • @Konstantin-Tokarev how I can check QtWebKit version?

    In my system I have libqt5webkit5-dev package installed at its version is
    5.212.0~alpha2-7ubuntu1. I assume this is the most recent version from your fork.

    Also I checked WebKit version with the following code

    >>> from PyQt5.QtWebKit import qWebKitVersion
    >>> print(qWebKitVersion())
    602.1
    

    Are there newest version?



  • @voltron No, that's what I was suggesting to you. Could you specify what JS features are you lacking?



  • @Konstantin-Tokarev I'm afraid no, I'm not a JS dev. The problem is that JS code I posted in the first message does not work with errors

    https://cdn.3dmapping.cloud/18.1.4/javascript/orbitgt_3dm_sdk.js line
    1: TypeError: a.call is not a function. (In 'a.call(this,t,e,n,r)',
    'a.call' is an instance of ProxyObject)
    

    I was able to identify that calls Array.from() and Object.assign() are missed, but maybe there are more.


Log in to reply
 

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