Do not report errors from injected javascript

Fixes continual error popups on Chrome for iOS
This commit is contained in:
Kovid Goyal 2017-05-29 10:21:06 +05:30
parent 2fbaa19cd6
commit 622a7fcafd
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 17 additions and 6 deletions

View File

@ -33,14 +33,19 @@ def remove_initial_progress_bar():
p.parentNode.removeChild(p) p.parentNode.removeChild(p)
def onerror(msg, script_url, line_number, column_number, error_object): def onerror(msg, script_url, line_number, column_number, error_object):
if error_object: if error_object is None:
console.log(error_object) # This happens for cross-domain errors (probably javascript injected
# into the browser via extensions/ userscripts and the like). It also
# happens all the time when using Chrom on Safari, so ignore this
# type of error
console.log(f'Unhandled error from external javascript, ignoring: {msg} {script_url} {line_number}')
return
console.log(error_object)
try: try:
fname = script_url.rpartition('/')[-1] or script_url fname = script_url.rpartition('/')[-1] or script_url
msg = msg + '<br><span style="font-size:smaller">' + 'Error at {}:{}:{}'.format(fname, line_number, column_number or '') + '</span>' msg = msg + '<br><span style="font-size:smaller">' + 'Error at {}:{}:{}'.format(fname, line_number, column_number or '') + '</span>'
details = '' details = ''
if error_object: details = traceback.format_exception(error_object).join('')
details = traceback.format_exception(error_object).join('')
error_dialog(_('Unhandled error'), msg, details) error_dialog(_('Unhandled error'), msg, details)
return True return True
except: except:

View File

@ -138,8 +138,14 @@ class IframeBoss:
self.send_message('print', string=' '.join(map(str, args))) self.send_message('print', string=' '.join(map(str, args)))
def onerror(self, msg, script_url, line_number, column_number, error_object): def onerror(self, msg, script_url, line_number, column_number, error_object):
if error_object: if error_object is None:
console.log(error_object) # This happens for cross-domain errors (probably javascript injected
# into the browser via extensions/ userscripts and the like). It also
# happens all the time when using Chrom on Safari, so ignore this
# type of error
console.log(f'Unhandled error from external javascript, ignoring: {msg} {script_url} {line_number}')
return
console.log(error_object)
try: try:
fname = script_url.rpartition('/')[-1] or script_url fname = script_url.rpartition('/')[-1] or script_url
msg = msg + '<br><span style="font-size:smaller">' + 'Error at {}:{}:{}'.format(fname, line_number, column_number or '') + '</span>' msg = msg + '<br><span style="font-size:smaller">' + 'Error at {}:{}:{}'.format(fname, line_number, column_number or '') + '</span>'