don't error out when non-latin characters written to js console

(some?) macOS users have an ascii encoding, so we need to escape
the non-ascii portions prior to writing
This commit is contained in:
Damien Elmes 2019-05-17 08:43:25 +10:00
parent 0008e6cb3f
commit 1f36a7112f

View file

@ -63,8 +63,10 @@ class AnkiWebPage(QWebEnginePage):
def javaScriptConsoleMessage(self, lvl, msg, line, srcID):
# not translated because console usually not visible,
# and may only accept ascii text
sys.stdout.write("JS error on line %(a)d: %(b)s" %
dict(a=line, b=msg+"\n"))
buf = "JS error on line %(a)d: %(b)s" % dict(a=line, b=msg+"\n")
# ensure we don't try to write characters the terminal can't handle
buf = buf.encode(sys.stdout.encoding, "backslashreplace").decode(sys.stdout.encoding)
sys.stdout.write(buf)
def acceptNavigationRequest(self, url, navType, isMainFrame):
if not isMainFrame: