问题
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