Remove Logs from PyQt5 Browser on Console

爷,独闯天下 提交于 2020-06-08 13:04:57

问题


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:


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


来源:https://stackoverflow.com/questions/54875167/remove-logs-from-pyqt5-browser-on-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!