mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 07:22:23 -04:00
Fixed javaScriptConsoleMessage showing 'error on line' for
all lines. The new output format is: JS info /_anki/reviewer.js:166 autoadd JS error /_anki/reviewer.js:240 Uncaught (in promise) NotAllowedError: play() can only be initiated by a user gesture.
This commit is contained in:
parent
a686f2cf44
commit
f3c561b6d9
1 changed files with 17 additions and 7 deletions
|
@ -67,15 +67,24 @@ class AnkiWebPage(QWebEnginePage): # type: ignore
|
||||||
script.setRunsOnSubFrames(False)
|
script.setRunsOnSubFrames(False)
|
||||||
self.profile().scripts().insert(script)
|
self.profile().scripts().insert(script)
|
||||||
|
|
||||||
def javaScriptConsoleMessage(self, lvl, msg, line, srcID):
|
def javaScriptConsoleMessage(self, level, msg, line, srcID):
|
||||||
# not translated because console usually not visible,
|
# not translated because console usually not visible,
|
||||||
# and may only accept ascii text
|
# and may only accept ascii text
|
||||||
buf = "JS error on line %(a)d: %(b)s" % dict(a=line, b=msg + "\n")
|
srcID = srcID.replace(AnkiWebView.webBundlePath("/"), "")
|
||||||
# ensure we don't try to write characters the terminal can't handle
|
if level == QWebEnginePage.InfoMessageLevel:
|
||||||
buf = buf.encode(sys.stdout.encoding, "backslashreplace").decode(
|
level = "info"
|
||||||
sys.stdout.encoding
|
elif level == QWebEnginePage.WarningMessageLevel:
|
||||||
|
level = "warning"
|
||||||
|
elif level == QWebEnginePage.ErrorMessageLevel:
|
||||||
|
level = "error"
|
||||||
|
buf = "JS %(t)s /%(f)s:%(a)d %(b)s" % dict(
|
||||||
|
t=level, a=line, f=srcID, b=msg + "\n"
|
||||||
)
|
)
|
||||||
sys.stdout.write(buf)
|
# ensure we don't try to write characters the terminal can't handle
|
||||||
|
buf = buf.encode(sys.stderr.encoding, "backslashreplace").decode(
|
||||||
|
sys.stderr.encoding
|
||||||
|
)
|
||||||
|
sys.stderr.write(buf)
|
||||||
|
|
||||||
def acceptNavigationRequest(self, url, navType, isMainFrame):
|
def acceptNavigationRequest(self, url, navType, isMainFrame):
|
||||||
if not isMainFrame:
|
if not isMainFrame:
|
||||||
|
@ -412,7 +421,8 @@ body {{ zoom: {}; background: {}; {} }}
|
||||||
# print(html)
|
# print(html)
|
||||||
self.setHtml(html)
|
self.setHtml(html)
|
||||||
|
|
||||||
def webBundlePath(self, path: str) -> str:
|
@classmethod
|
||||||
|
def webBundlePath(cls, path: str) -> str:
|
||||||
from aqt import mw
|
from aqt import mw
|
||||||
|
|
||||||
if path.startswith("/"):
|
if path.startswith("/"):
|
||||||
|
|
Loading…
Reference in a new issue