[browser] hyperlinks with target="_blank" do not open

Bug #1129281 reported by Rachel Liu
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
webbrowser-app
Fix Released
High
Olivier Tilloy

Bug Description

This can easily be observed in the twitter web app.

When you click on an external link, it does not load the content or takes to the browser to open the URL.

Tested on phone and tablet, build #86

Tags: mwc

Related branches

Rachel Liu (rachelliu)
tags: added: mwc
Revision history for this message
Olivier Tilloy (osomon) wrote :

Rachel, can you please detail the steps you’re taking to reproduce this bug? It’s unclear to me from where I should be clicking on an external link.

Changed in manhattan:
status: New → Incomplete
Revision history for this message
Rachel Liu (rachelliu) wrote :

Olivier, please do the following:

Click on Twitter app
Login
On the 'home' tab and look for an article with a URL
Try clicking on the URL, you can select it but it doesn't load the page (either on the web app or open it from the browser)

Changed in manhattan:
assignee: nobody → Olivier Tilloy (osomon)
Revision history for this message
Olivier Tilloy (osomon) wrote :

Got it, I can reproduce. After some investigation, it turns out the link in tweets have the "target" attribute set to "_blank", which is a special, deprecated way of requesting to open a new window/tab. It appears the webview doesn’t handle this well by default. I need to look into how we can support them (for now we’d just open them in the same view, ignoring the target attribute).

summary: - [twitter webapp] external link doesn't load
+ [browser] hyperlinks with "target=_blank" do not open
summary: - [browser] hyperlinks with "target=_blank" do not open
+ [browser] hyperlinks with target="_blank" do not open
Changed in manhattan:
status: Incomplete → Confirmed
description: updated
Revision history for this message
Olivier Tilloy (osomon) wrote :

This seems to be a bug in webkit itself. When clicking a link that has "target=_blank", the navigationRequested() signal (http://doc-snapshot.qt-project.org/5.0/qtwebkit/qml-qtwebkit3-webview.html#onNavigationRequested-signal) is not emitted.

Related upstream bug reports:
  https://bugs.webkit.org/show_bug.cgi?id=76416
  https://bugs.webkit.org/show_bug.cgi?id=91779

Revision history for this message
Olivier Tilloy (osomon) wrote :

What’s missing on the webkit side is apparently for QtWebPagePolicyClient to implement the decidePolicyForNewWindowAction(…) callback. This doesn’t seem to be implemented, even in the latest trunk.

Revision history for this message
Olivier Tilloy (osomon) wrote :

Until a real fix is implemented in webkit, we might be able to work around the problem by using javascript event delegation to install a handler for the page when it’s loaded and intercept all hyperlink activations.

Olivier Tilloy (osomon)
Changed in manhattan:
importance: Undecided → High
Olivier Tilloy (osomon)
Changed in manhattan:
status: Confirmed → In Progress
Revision history for this message
Olivier Tilloy (osomon) wrote :

I have linked a branch that implements the suggested idea (use javascript event delegation to install a handler for the page when it’s loaded and intercept all hyperlink activations). This works very well for normal hyperlinks with target = "_blank".

However, it looks like twitter does additional processing of those links. According to the webkit web inspector, an event listener is installed on the document (from https://platform.twitter.com/widgets.js) which does the following:

    function p(a) {
        a = a || window.event;
        var b = a.target || a.srcElement, c, d, e;
        while (b && b.nodeName.toLowerCase() !== "a") b = b.parentNode;
        b && b.nodeName.toLowerCase() === "a" && b.href && (c = b.href.match(f), c && (e = o(b.href), e = e.replace(/^http[:]/, "https:"), e = e.replace(/^\/\//, "https://"), q(e, b), a.returnValue = !1, a.preventDefault && a.preventDefault()));
    }

So, for some reason that I don’t fully understand yet, this listener cancels the event without stopping further propagation of it (see https://developer.mozilla.org/en-US/docs/DOM/event.preventDefault). I suspect this listener is what prevents my custom handler from getting the click event. Needs more investigation.

Revision history for this message
Rachel Liu (rachelliu) wrote :

When testing on Facebook app, and finding a bitly link as an example it does nothing when you click on the link. Need to investigate if this is a similar issue to Twitter.

Olivier Tilloy (osomon)
Changed in manhattan:
milestone: none → update-2
status: In Progress → Fix Committed
Revision history for this message
Olivier Tilloy (osomon) wrote :

The fix that was just committed doesn’t address the issue originally reported, because of the additional processing that twitter does of those links. I filed bug #1159857 to track this issue separately.

Revision history for this message
Olivier Tilloy (osomon) wrote :

Fixed in webbrowser-app 0.17.

Changed in manhattan:
status: Fix Committed → Fix Released
information type: Proprietary → Public
affects: manhattan → notes-app
Changed in notes-app:
milestone: ubuntu-13.04-month-5 → none
affects: notes-app → webbrowser-app
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.