mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Prevent un-lloadable resources in link tags (non-CSS stylesheets) from causing the resource loading check to timeout
This commit is contained in:
parent
45fbdbea30
commit
b0cf1e8c05
@ -215,6 +215,7 @@ class Container(ContainerBase):
|
||||
resource_template = link_uid + '|{}|'
|
||||
xlink_xpath = XPath('//*[@xl:href]')
|
||||
link_xpath = XPath('//h:a[@href]')
|
||||
res_link_xpath = XPath('//h:link[@href]')
|
||||
|
||||
def link_replacer(base, url):
|
||||
if url.startswith('#'):
|
||||
@ -249,6 +250,14 @@ class Container(ContainerBase):
|
||||
elif mt in OEB_DOCS:
|
||||
self.virtualized_names.add(name)
|
||||
root = self.parsed(name)
|
||||
for link in res_link_xpath(root):
|
||||
ltype = (link.get('type') or 'text/css').lower()
|
||||
rel = (link.get('rel') or 'stylesheet').lower()
|
||||
if ltype != 'text/css' or rel != 'stylesheet':
|
||||
# This link will not be loaded by the browser anyway
|
||||
# and will causes the resource load check to hang
|
||||
link.attrib.clear()
|
||||
changed.add(name)
|
||||
rewrite_links(root, partial(link_replacer, name))
|
||||
for a in link_xpath(root):
|
||||
href = a.get('href')
|
||||
|
@ -229,11 +229,13 @@ def unserialize_html(serialized_data, proceed):
|
||||
clear(document.head, document.body)
|
||||
load_required = set()
|
||||
proceeded = False
|
||||
hang_timeout = 5
|
||||
|
||||
def hangcheck():
|
||||
nonlocal proceeded
|
||||
if not proceeded:
|
||||
proceeded = True
|
||||
print('WARNING: All resources did not load in {} seconds, proceeding anyway ({} resources left)'.format(hang_timeout, load_required.length))
|
||||
proceed()
|
||||
|
||||
def onload():
|
||||
@ -258,7 +260,7 @@ def unserialize_html(serialized_data, proceed):
|
||||
ev.initEvent('DOMContentLoaded', True, True)
|
||||
document.dispatchEvent(ev)
|
||||
if load_required.length:
|
||||
setTimeout(hangcheck, 5000)
|
||||
setTimeout(hangcheck, hang_timeout * 1000)
|
||||
else:
|
||||
proceeded = True
|
||||
proceed()
|
||||
|
Loading…
x
Reference in New Issue
Block a user