Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tab is opened twice #3579

Closed
james64 opened this issue May 28, 2020 · 12 comments · Fixed by #3985
Closed

Tab is opened twice #3579

james64 opened this issue May 28, 2020 · 12 comments · Fixed by #3985

Comments

@james64
Copy link

james64 commented May 28, 2020

Describe the bug
I do not know whether issue is on vimium's side. I would like to ask for help determining that. See below for issue description.

To Reproduce
Steps to reproduce the behavior:

  1. Go to qwant.com search engine
  2. Enter a search term of your choice
  3. When a result is clicked by mouse or is opened by vimium into separate tab (f shift <code>) everything is ok
  4. If however a link is opened by vimium into this tab (f <code>) then new tab is opened twice in two separate new tabs. Issue is not about opening in new tab vs this tab. But it should not be opened twice.

Browser and Vimium version
Firefox - 76.0.1
OS - Linux 4.19.122-1-MANJARO
Vimium - 1.66

Please let me know if I can help debugging this.

@gdh1995
Copy link
Contributor

gdh1995 commented May 28, 2020

Usually Firefox has a strict popup-window blocker, which will block Vimium's requests of clicking a link and opening a new tab for it. To work around it, Vimium has used a special part of code to create a tab with the link's URL (using web-extension APIs, which is not blocked).

According to what you met, it seems that this blocker has some changes and now passes Vimium's normal requests (the one using not web-extension APIs but "clicking" event). Maybe it's because of a special browser setting, a special flag in about:config, an environment variable, or something unexpected else.

@lydell
Copy link

lydell commented May 28, 2020

To work around it, Vimium has used a special part of code to create a tab with the link's URL (using web-extension APIs, which is not blocked).

@gdh1995 Can you link to that piece of code, please? I’m curious how it works :)

@gdh1995
Copy link
Contributor

gdh1995 commented May 29, 2020

vimium/lib/dom_utils.js

Lines 323 to 337 in 6aecf63

const defaultActionShouldTrigger =
Utils.isFirefox() && (Object.keys(modifiers).length === 0) && (event === "click") &&
(element.target === "_blank") && element.href &&
!element.hasAttribute("onclick") && !element.hasAttribute("_vimium-has-onclick-listener") ?
// Simulating a click on a target "_blank" element triggers the Firefox popup blocker.
// Note(smblott) This will be incorrect if there is a click listener on the element.
true
:
this.simulateMouseEvent(event, element, modifiers);
if ((event === "click") && defaultActionShouldTrigger && Utils.isFirefox()) {
// Firefox doesn't (currently) trigger the default action for modified keys.
if ((0 < Object.keys(modifiers).length) || (element.target === "_blank")) {
DomUtils.simulateClickDefaultAction(element, modifiers);
}
}

@lydell
Copy link

lydell commented May 29, 2020

Cool, thanks! I’m not sure if it helps, but I’ve implemented workarounds for Firefox’s popup blocker too: https://github.com/lydell/LinkHints/blob/efa18fdfbf95016bd706b83a2d51545cb157b440/src/worker/Program.js#L1337-L1631

@james64
Copy link
Author

james64 commented May 29, 2020

@gdh1995 that also explains why firefox was showing me those popup-blocked msg even though there was no pop-up in sight. Seeing that msg I explicitly allowed popus from qwant. That's why normal request passed.

Removing qwant from white list indeed stops second tab from opening. I get that popup-block msg back. I need to dont-show-this-msg to remove it.

Follow-up questiion. Is there a simple way to explain why this yellow block msg is not happening on all sites?

@gdh1995
Copy link
Contributor

gdh1995 commented May 29, 2020

If a page hooks click events and use JavaScript code to do some UI changes, then there may be no block message.

This often occurs when JavaScript code (including those of extensions) wants to trigger <a target="_blank">, though I'm not sure whether Firefox blocks on all such types of pages or not. Compared with Chrome, Firefox has too many limits on web-extensions.

@james64
Copy link
Author

james64 commented May 29, 2020

Thanks for all the information!

@james64 james64 closed this as completed May 29, 2020
@lydell
Copy link

lydell commented May 29, 2020

I don’t think this issue should be closed. It is possible to avoid the double-open and popup blocker (it works in my extension).

@gdh1995
Copy link
Contributor

gdh1995 commented May 29, 2020

@lydell, the way of adding click listener on all items in event.path looks a bit long and too tricky, and:

  • it can not work if a host script caches methods like Event.prototype.preventDefault
  • it can not work if another extension register some listeners on the event instance.

@lydell
Copy link

lydell commented May 31, 2020

Yes, it’s not perfect but it does work in a lot of situations. 🤷‍♂️

@Artturin
Copy link

Artturin commented Nov 29, 2021

this is happening to me on github now but instead it happens when i open a link into a new tab. started today or yesterday

@s-marios
Copy link

this is happening to me on github now but instead it happens when i open a link into a new tab. started today or yesterday

Can confirm, I'm also affected on Firefox Nightly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants