3

I have a PyQt5 application Virtual Desktop that has a built-in browser. When I use the browser, I get JS errors from the browser similar to how Chrome puts JS and HTML errors in the "Web Inspector". How do I get rid of those errors.

To replicate the errors, download Virtual Desktop and install PyQt from PYPI. You'll need to run main.py, select a QStyle, and click on the Browser (next to the power button). Go to any website (google for example) and switch back to your console. You will notice that the console is populated with JS errors.

1 Answer 1

3

I do not observe the problem when using your project but I had this problem before and the solution was to write the javaScriptConsoleMessage() method, eliminating the default behavior.

from PyQt5 import QtCore, QtWidgets, QtWebEngineWidgets 

class WebEnginePage(QtWebEngineWidgets.QWebEnginePage):
    def javaScriptConsoleMessage(self, level, msg, line, sourceID):
        pass

if __name__ == '__main__':
    import sys
    app = QtWidgets.QApplication(sys.argv)
    view = QtWebEngineWidgets.QWebEngineView()
    page = WebEnginePage(view)
    view.setPage(page)
    view.load(QtCore.QUrl("https://www.google.com/"))
    view.show()
    sys.exit(app.exec_())
2
  • I'm not sure how you would implement your solution in my program because the browser (and all the other applications) are QMdiSubWindow. Because of that, my program is designed differently than yours. Commented Feb 27, 2019 at 19:25
  • @DS_SecretStudios I made you a PR, check your repository
    – eyllanesc
    Commented Feb 27, 2019 at 19:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.