summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Albrecht <palbrecht@mailbox.org>2023-08-23 09:51:29 +0200
committerPhilipp Albrecht <palbrecht@mailbox.org>2023-08-28 13:17:08 +0200
commit43ca14aa5339b828f64ca2b0150f75604056062d (patch)
treeb4b332763cbe2673e9c8e274c955227d13d2d5c4
parent3974725932c2e3e06bd16e73a3a6b6f15e1beec4 (diff)
downloadqutebrowser-43ca14aa5339b828f64ca2b0150f75604056062d.tar.gz
qutebrowser-43ca14aa5339b828f64ca2b0150f75604056062d.zip
Allow hinted navigation from file:// to remote origins
As of Qt 6 navigating from local to remote origins requires user interaction. This broke following links to remote origins via hints from a local file (e.g. `bookmarks.html`), because hints use JavaScript to open links by default. Example: 1. Have a local `bookmarks.html`: ```html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>My bookmarks</title> </head> <body> <a href="https://example.com/" id="link">some bookmark</a> </body> </html> ``` 2. Open that local `bookmarks.html` in qutebrowser (e.g. `:open path/to/bookmarks.html`) 3. Start hinting 4. Follow a link to a bookmark (e.g. https://example.com/) 5. Instead of the link opening, be presented with `Your internet access is blocked` error To fix this, we simply force a user interaction for all hints on file:// URLs (like we did for `qute://` URLs in 8defe1ae44c1c524e937ae08ed16052ee0724e0f). We skip the end2end test for webkit, because webkit does not support URLSearchParams[1] used in `tests/end2end/data/hints/link_inject.html` [1] https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams
-rw-r--r--qutebrowser/browser/webengine/webengineelem.py16
-rw-r--r--tests/end2end/data/hints/link_inject.html19
-rw-r--r--tests/end2end/features/hints.feature7
3 files changed, 35 insertions, 7 deletions
diff --git a/qutebrowser/browser/webengine/webengineelem.py b/qutebrowser/browser/webengine/webengineelem.py
index 20c3a36d4..c387ebbcf 100644
--- a/qutebrowser/browser/webengine/webengineelem.py
+++ b/qutebrowser/browser/webengine/webengineelem.py
@@ -215,14 +215,16 @@ class WebEngineElement(webelem.AbstractWebElement):
return False
# Qt 6.3+ needs a user interaction to allow navigations from qute:// to
- # outside qute:// (like e.g. on qute://bookmarks).
+ # outside qute:// (like e.g. on qute://bookmarks), as well as from file:// to
+ # outside of file:// (e.g. users having a local bookmarks.html).
versions = version.qtwebengine_versions()
- if (
- baseurl.scheme() == "qute" and
- url.scheme() != "qute" and
- versions.webengine >= utils.VersionNumber(6, 3)
- ):
- return True
+ for scheme in ["qute", "file"]:
+ if (
+ baseurl.scheme() == scheme and
+ url.scheme() != scheme and
+ versions.webengine >= utils.VersionNumber(6, 3)
+ ):
+ return True
return url.scheme() not in urlutils.WEBENGINE_SCHEMES
diff --git a/tests/end2end/data/hints/link_inject.html b/tests/end2end/data/hints/link_inject.html
new file mode 100644
index 000000000..7ef352028
--- /dev/null
+++ b/tests/end2end/data/hints/link_inject.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>A link to use hints on</title>
+ <script>
+ function injectPort() {
+ const queryString = document.location.search;
+ const params = new URLSearchParams(queryString);
+ const port = params.get("port")
+ let link = document.getElementById("link");
+ link.href = link.href.replace("<port>", port);
+ }
+ </script>
+ </head>
+ <body onload="injectPort()">
+ <a href="http://localhost:<port>/data/hello.txt" id="link">Follow me!</a>
+ </body>
+</html>
diff --git a/tests/end2end/features/hints.feature b/tests/end2end/features/hints.feature
index 80348c908..ddf42132f 100644
--- a/tests/end2end/features/hints.feature
+++ b/tests/end2end/features/hints.feature
@@ -44,6 +44,13 @@ Feature: Using hints
- data/hints/link_blank.html
- data/hello.txt
+ # https://github.com/qutebrowser/qutebrowser/issues/7842
+ @qtwebkit_skip
+ Scenario: Following a hint from a local file to a remote origin
+ When I open file://(testdata)/hints/link_inject.html?port=(port)
+ And I hint with args "links" and follow a
+ Then data/hello.txt should be loaded
+
Scenario: Following a hint to link with sub-element and force to open in current tab.
When I open data/hints/link_span.html
And I hint with args "links current" and follow a