From 1799b7926a0202497a88e4ee1fdb232f06ab8e3a Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 14 Jan 2019 22:22:56 +0100 Subject: [PATCH] Make console available in PAC files --- doc/changelog.asciidoc | 1 + qutebrowser/browser/network/pac.py | 2 ++ tests/unit/browser/webkit/network/test_pac.py | 14 ++++++++++++++ 3 files changed, 17 insertions(+) diff --git a/doc/changelog.asciidoc b/doc/changelog.asciidoc index ceab9d043..a116b53e6 100644 --- a/doc/changelog.asciidoc +++ b/doc/changelog.asciidoc @@ -54,6 +54,7 @@ Changed - Various small performance improvements for hints and the completion. - The Wayland check for QtWebEngine is now disabled on Qt >= 5.11.2, as those versions should work without any issues. +- The JavaScript `console` object is now available in PAC files. Fixed ~~~~~ diff --git a/qutebrowser/browser/network/pac.py b/qutebrowser/browser/network/pac.py index 1c6075945..bd060820b 100644 --- a/qutebrowser/browser/network/pac.py +++ b/qutebrowser/browser/network/pac.py @@ -180,6 +180,8 @@ class PACResolver: """ self._engine = QJSEngine() + self._engine.installExtensions(QJSEngine.ConsoleExtension) + self._ctx = _PACContext(self._engine) self._engine.globalObject().setProperty( "PAC", self._engine.newQObject(self._ctx)) diff --git a/tests/unit/browser/webkit/network/test_pac.py b/tests/unit/browser/webkit/network/test_pac.py index 8c03c6cee..5aebecbf2 100644 --- a/tests/unit/browser/webkit/network/test_pac.py +++ b/tests/unit/browser/webkit/network/test_pac.py @@ -205,6 +205,20 @@ def test_secret_url(url, has_secret, from_file): res.resolve(QNetworkProxyQuery(QUrl(url)), from_file=from_file) +def test_logging(qtlog): + """Make sure console.log() works for PAC files.""" + test_str = """ + function FindProxyForURL(domain, host) { + console.log("logging test"); + return "DIRECT"; + } + """ + res = pac.PACResolver(test_str) + res.resolve(QNetworkProxyQuery(QUrl("https://example.com/test"))) + assert len(qtlog.records) == 1 + assert qtlog.records[0].message == 'logging test' + + def fetcher_test(test_str): class PACHandler(http.server.BaseHTTPRequestHandler): def do_GET(self):