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 8defe1ae44).
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
This commit is contained in:
parent
3974725932
commit
43ca14aa53
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue