From b243acf172206efcaab5a9c93ad4f6858f2c8c6a Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Mon, 23 Nov 2015 22:41:00 +0100 Subject: [PATCH] Add a nice error page when pdfjs is not found --- qutebrowser/browser/webpage.py | 7 ++- qutebrowser/html/no_pdfjs.html | 112 +++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 qutebrowser/html/no_pdfjs.html diff --git a/qutebrowser/browser/webpage.py b/qutebrowser/browser/webpage.py index fca9ee7a5..be24a7fe0 100644 --- a/qutebrowser/browser/webpage.py +++ b/qutebrowser/browser/webpage.py @@ -220,7 +220,12 @@ class BrowserPage(QWebPage): def _show_pdfjs(self, reply): """Show the reply with pdfjs.""" - page = pdfjs.generate_pdfjs_page(reply.url()).encode('utf-8') + try: + page = pdfjs.generate_pdfjs_page(reply.url()).encode('utf-8') + except pdfjs.PDFJSNotFound: + page = (jinja.env.get_template('no_pdfjs.html') + .render(url=reply.url().toDisplayString()) + .encode('utf-8')) self.mainFrame().setContent(page, 'text/html', reply.url()) reply.deleteLater() diff --git a/qutebrowser/html/no_pdfjs.html b/qutebrowser/html/no_pdfjs.html new file mode 100644 index 000000000..fcfc1d3f8 --- /dev/null +++ b/qutebrowser/html/no_pdfjs.html @@ -0,0 +1,112 @@ +{% extends "base.html" %} +{% block style %} +{{ super() }} +* { + margin: 0px 0px; + padding: 0px 0px; +} + +body { + font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; + -webkit-text-size-adjust: none; + color: #333333; + background-color: #EEEEEE; + font-size: 1.2em; +} + +#error-container { + margin-left: 20px; + margin-right: 20px; + margin-top: 20px; + border: 1px solid #CCCCCC; + box-shadow: 0px 0px 6px rgba(0, 0, 0, 0.20); + border-radius: 5px; + background-color: #FFFFFF; + padding: 20px 20px; +} + +#header { + border-bottom: 1px solid #CCC; +} + +.qutebrowser-broken { + display: block; + width: 100%; +} + +td { + margin-top: 20px; + color: #555; +} + +h1, h2 { + font-weight: normal; + color: #1e89c6; + margin-bottom: 10px; +} + +ul { + margin-left: 20px; + margin-top: 20px; + margin-bottom: 20px; +} + +li { + margin-top: 10px; + margin-bottom: 10px; +} +{% endblock %} + +{% block content %} +
+ + + + + +
+ + +

No pdf.js installation found

+

Error while opening {{ url }}:
+

qutebrowser can't find a suitable pdf.js installation

+ +

It looks like you set content -> enable-pdfjs + to true but qutebrowser can't find the required files.

+ +
+ +

Possible fixes

+
    +
  • + Disable content -> enable-pdfjs and reload the page. + You will need to download the pdf-file and open it with an external + tool instead. +
  • + +
  • + If you have installed a packaged version of qutebrowser, make sure + the required packages for pdf.js are also installed. +
  • + +
  • + If you have installed a pdf.js package and qutebrowser still can't + find it, please send us a report with your system and the package + name, so we can add it to the list of supported packages. +
  • + +
  • + If you're running a self-built version or the source version, make + sure you have pdf.js in qutebrowser/3rdparty/pdfjs. + You can use the scripts/dev/update_3rdparty.py script + to download the latest version. +
  • +
+ +

+ If none of these fixes work for you, please send us a bug report so + we can fix the issue. +

+
+
+{% endblock %}