"Open all external links in a new tab" does not work when you select some text

Awesome sleuthing Don, would you like to submit a PR?


Thanks Sam, I just testing it more closely before submitting and it seems this is not enough unfortunately. This solution only works with Chrome.


Here’s the piece of code causing the bug (from app/assets/javascripts/discourse/app/lib/click-track.js)

    // Cancel click if triggered as part of selection.
    const selection = window.getSelection();
    if (selection.type === "Range" || selection.rangeCount > 0) {
      if (selectedText() !== "") {
        return true;

Removing this code solves the problem and doesn’t appear to break tests (I have some tests failing before and after the change for some reason but no new ones apparently).
So I’m wondering whether this code does anything useful because one thing it sure doesn’t do is what it says it does, otherwise the bug reporter would experience no link follow at all upon ‘select + click’ but that’s not his complaint.
Can someone share what this code is supposed to accomplish?

1 Like

Maybe it’s made to prevent opening links in new tabs when just selecting some text to quote our copy?

When the code you found is deactivated and when you have the “Open all external links in a new tab” option checked,

Could you try to select (mouse down, drag, mouse up) some text that includes links to see if it does not open any of them?

Try with a selection that surrounds links and also try with a selection that ends in the middle of a link, maybe.

The selection should always just select, not open links.

Yes, such selections work as expected: without following links or opening them in new tabs.

1 Like

I vaguely recall there was a workaround for a specific browser, maybe try in Safari/Firefox/Chrome with a selection to see if any trigger it?

1 Like

Works on Firefox, Chrome. How should I try Safari on Ubuntu?

1 Like

Is your dev server accessible on your wi-fi so that you could also test with your smartphone?

Maybe the touch screen finger drag events are triggering the open links.

You could add this smartphone browser (Firefox, Chromium-based or Safari) to your tested browser list. :sunglasses:

And, but the way, thank you so very much for your work on this bug!!

I found this reason for this cancel code, apparently:

Prevent a click if the user select content in a topic and release the mouse over a link.

[deleted topic]

Interesting comment:

I only have access to windows platform for testing.

this fix can be tested easily as the file can be pasted as a whole into the console.

@sam you know which file we should paste in the console after loading a topic page?
@Aleksey_Bogdanov could give that file and I could paste it in my Windows Vivaldi, Firefox, Android 9 Kiwi browser consoles, and you could paste it in your iOS, Mac OS Safari.

I don’t think it works like that any more.

1 Like

No problem detected in Chrome and Firefox on Android although I struggle to select in Firefox as liberally.

1 Like

It was the same before your change, right?

Yes, same as before. Just not sure how to select something other than a word or the whole document.

Just long press on a word near a link, then release, then drag one of the extremities of the selection until you reach the center of the link text, then release again.

Off topic (different problem), but worth mentioning:

I made an MP4 video but it is refused by disclose (Android 9 Kiwi and Firefox):

Sorry, the file you are trying to upload is not authorised (authorised extensions: jpg, jpeg, png, gif, pdf, csv, gz, json, svg, mp4, txt, docx, mov, tex, zip, webm, heic, heif, webp, avif).

DCIM/ScreenRecorder/Screenrecorder-2023-01-10-21-10-05-130.mp4 1.36 MB

Yes, that works too.

1 Like

Do you want to open a PR about this? If not I will do it.

I’ll open one shortly.

1 Like

Feel free to ping me on it (j.jaffeux) I will test few things with it and then merge if all good.