diff --git a/src/calibre/gui2/viewer/web_view.py b/src/calibre/gui2/viewer/web_view.py index b5e2553897..6c7298d564 100644 --- a/src/calibre/gui2/viewer/web_view.py +++ b/src/calibre/gui2/viewer/web_view.py @@ -153,12 +153,9 @@ class UrlSchemeHandler(QWebEngineUrlSchemeHandler): return self.fail_request(rq) if name.startswith('book/'): name = name.partition('/')[2] - if name == '__index__': + if name in ('__index__', '__popup__'): send_reply(rq, 'text/html', b'
\xa0
') return - elif name == '__popup__': - send_reply(rq, 'text/html', b'
\xa0
') - return try: data, mime_type = get_data(name) if data is None: @@ -196,7 +193,7 @@ class UrlSchemeHandler(QWebEngineUrlSchemeHandler): if fail_code is None: fail_code = QWebEngineUrlRequestJob.Error.UrlNotFound rq.fail(fail_code) - prints("Blocking FAKE_PROTOCOL request: {}".format(rq.requestUrl().toString())) + prints("Blocking FAKE_PROTOCOL request: {} with code: {}".format(rq.requestUrl().toString(), fail_code)) # }}} diff --git a/src/pyj/iframe_comm.pyj b/src/pyj/iframe_comm.pyj index d8a4d78bd5..851daeb8b9 100644 --- a/src/pyj/iframe_comm.pyj +++ b/src/pyj/iframe_comm.pyj @@ -55,7 +55,7 @@ class IframeWrapper: self.messenger = Messenger() self.iframe_id = ensure_id(iframe, 'content-iframe') if ':' in entry_point: - self.needs_init = False + self.needs_init = iframe.src is not entry_point self.srcdoc_created = True self.constructor_url = entry_point self.entry_point = None @@ -115,6 +115,8 @@ class IframeWrapper: self.encrypted_communications = False def _send_message(self, action, encrypted, data): + if not self.ready: + return data.action = action msg = {'data':data, 'encrypted': encrypted} if encrypted: diff --git a/src/pyj/read_book/iframe.pyj b/src/pyj/read_book/iframe.pyj index 4954aec0f1..0a23708076 100644 --- a/src/pyj/read_book/iframe.pyj +++ b/src/pyj/read_book/iframe.pyj @@ -1006,4 +1006,5 @@ class IframeBoss: def main(): - main.boss = IframeBoss() + if not main.boss: + main.boss = IframeBoss() diff --git a/src/pyj/read_book/view.pyj b/src/pyj/read_book/view.pyj index f02ac35559..9cf29c06aa 100644 --- a/src/pyj/read_book/view.pyj +++ b/src/pyj/read_book/view.pyj @@ -885,12 +885,14 @@ class View: is_current_book = self.book and self.book.key == book.key self.book_load_started = True if not is_current_book: - self.iframe_wrapper.reset() - self.content_popup_overlay.reset() + if self.book: + self.iframe_wrapper.reset() + self.content_popup_overlay.reset() self.loaded_resources = {} self.content_popup_overlay.loaded_resources = {} self.timers.start_book(book) self.search_overlay.clear_caches(book) + self.iframe_wrapper.init() unkey = username_key(get_interface_data().username) self.book = current_book.book = book hl = None diff --git a/src/pyj/viewer-main.pyj b/src/pyj/viewer-main.pyj index a3f4600088..adeac66e34 100644 --- a/src/pyj/viewer-main.pyj +++ b/src/pyj/viewer-main.pyj @@ -442,8 +442,7 @@ if window is window.top: , 0) # We do this after event loop ticks over to avoid catching popstate events that some browsers send on page load else: # iframe - div = document.getElementById('calibre-viewer-footnote-iframe') - if div: - footnotes_main() - else: + if document.location.pathname.endsWith('/__index__'): iframe_main() + elif document.location.pathname.endsWith('/__popup__'): + footnotes_main()