From 1f36a7112f2233a21be415f943a656b56b7f9808 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 17 May 2019 08:43:25 +1000 Subject: [PATCH] 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 --- aqt/webview.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/aqt/webview.py b/aqt/webview.py index 9c1f42026..f6b60c860 100644 --- a/aqt/webview.py +++ b/aqt/webview.py @@ -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: