Remove Logs from PyQt5 Browser on Console

前端 未结 1 571
春和景丽
春和景丽 2021-01-15 02:47

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 error

1条回答
  •  执念已碎
    2021-01-15 03:37

    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_())
    

    0 讨论(0)
提交回复
热议问题