Try to get the error ... not sure about this ...
source is undefined when you type stuff in the console, I *think* this is the only scenario? But maybe not? <script> setInterval(function() { if (window.__qute_jseval__) { throw new Error('jseval hack failed. Sorry :-( ' + window.__qute_jseval__); } }, 1); </script>
This commit is contained in:
parent
27fdf4903a
commit
85eea17b18
@ -1510,3 +1510,23 @@ class CommandDispatcher:
|
||||
view = self._current_widget()
|
||||
for _ in range(count):
|
||||
view.triggerPageAction(member)
|
||||
|
||||
@cmdutils.register(instance='command-dispatcher', scope='window',
|
||||
maxsplit=0, no_cmd_split=True)
|
||||
def jseval(self, js):
|
||||
"""Evaluate a JavaScript string.
|
||||
|
||||
Args:
|
||||
s: The string to evaluate.
|
||||
"""
|
||||
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
||||
window='last-focused')
|
||||
out = tabbed_browser.widget(0).page().mainFrame().evaluateJavaScript(
|
||||
'window.__qute_jseval__ = true;\n' + js)
|
||||
|
||||
if out is not None:
|
||||
message.info(self._win_id, out)
|
||||
elif tabbed_browser.widget(0).page().jseval_error:
|
||||
message.error(self._win_id,
|
||||
tabbed_browser.widget(0).page().jseval_error)
|
||||
tabbed_browser.widget(0).page().jseval_error = None
|
||||
|
@ -63,6 +63,7 @@ class BrowserPage(QWebPage):
|
||||
def __init__(self, win_id, tab_id, parent=None):
|
||||
super().__init__(parent)
|
||||
self._win_id = win_id
|
||||
self.jseval_error = None
|
||||
self._is_shutting_down = False
|
||||
self._extension_handlers = {
|
||||
QWebPage.ErrorPageExtension: self._handle_errorpage,
|
||||
@ -497,6 +498,16 @@ class BrowserPage(QWebPage):
|
||||
|
||||
def javaScriptConsoleMessage(self, msg, line, source):
|
||||
"""Override javaScriptConsoleMessage to use debug log."""
|
||||
|
||||
jseval = self.mainFrame().evaluateJavaScript('window.__qute_jseval__')
|
||||
if jseval:
|
||||
self.mainFrame().evaluateJavaScript('window.__qute_jseval__ = undefined;')
|
||||
if source == 'undefined' and jseval:
|
||||
self.mainFrame().evaluateJavaScript('window.__qute_jseval__ = false;')
|
||||
print('jseval errror ->', jseval)
|
||||
self.jseval_error = 'Error on line {}: {}'.format(line, msg)
|
||||
print('other js error ->', msg, line, source)
|
||||
|
||||
if config.get('general', 'log-javascript-console'):
|
||||
log.js.debug("[{}:{}] {}".format(source, line, msg))
|
||||
|
||||
|
@ -111,19 +111,6 @@ def message_warning(win_id, text):
|
||||
message.warning(win_id, text)
|
||||
|
||||
|
||||
@cmdutils.register(maxsplit=0, no_cmd_split=True)
|
||||
def jseval(s):
|
||||
"""Evaluate a JavaScript string.
|
||||
|
||||
Args:
|
||||
s: The string to evaluate.
|
||||
"""
|
||||
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
||||
window='last-focused')
|
||||
message_info(tabbed_browser.widget(0)
|
||||
.page().mainFrame().evaluateJavaScript(s))
|
||||
|
||||
|
||||
@cmdutils.register(debug=True)
|
||||
def debug_crash(typ: {'type': ('exception', 'segfault')}='exception'):
|
||||
"""Crash for debugging purposes.
|
||||
|
Loading…
Reference in New Issue
Block a user