Skip to content

Firefox: Simulate default action for clicking links with link hints #2602

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

Merged
merged 4 commits into from
Sep 25, 2017

Conversation

mrmr1993
Copy link
Contributor

This makes the LinkHints.activateModeToOpenInNew{,Foreground}Tab commands work as expected on Firefox.

Currently the flag (simulateClickDefaultAction) is hardcoded on, which opens tabs twice in Chrome for the affected cases. It could be an option, use UA sniffing, or both (default set by UA sniffing), so I've left it for now.

@smblott-github this is a big usability win (currently FF can only open links in the current page).

@philc
Copy link
Owner

philc commented Aug 17, 2017

Any reason to delay merging this?

@mrmr1993
Copy link
Contributor Author

mrmr1993 commented Aug 17, 2017

simulateClickDefaultAction needs to be set differently on the FF side vs. the Chrome side, so a decision needs to be made on how to do that. I'll push a UA sniffing commit here shortly.

AFAIC, this is otherwise mergeable. I don't like that we have to do it or how it's done, but it does work.

@philc
Copy link
Owner

philc commented Aug 17, 2017

Sorry, I didn't read the PR description carefully enough. Thanks for clarifying. Yes, we need browser-branching before merging =)

@mrmr1993
Copy link
Contributor Author

Pushed UA sniffing for Firefox (as Utils.isFirefox). This should now be ready to go 🎉

I added a small change that gets rid of the lag when reloading the extension on FF; I can extract it out if need be. See comment on the commit for more.

@@ -5,6 +5,7 @@ root = exports ? window
chrome.runtime.onInstalled.addListener ({ reason }) ->
# See https://developer.chrome.com/extensions/runtime#event-onInstalled
return if reason in [ "chrome_update", "shared_module_update" ]
return if Utils.isFirefox()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why to do nothing on runtime.onInstalled if the browser is Firefox?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-injecting our content scripts doesn't work properly (ie. doesn't activate Vimium in tabs before they've been reloaded) on Firefox, and it makes the browser lag considerably while it's doing it. It was annoying me while testing, so I disabled it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it does fail. Thanks! Then I want to test the update notification if you haven't, in order to ensure nothing is working on Firefox.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test the update notification if you haven't

I haven't. Go for it.

@mrmr1993
Copy link
Contributor Author

@smblott-github @philc can this be merged? I've been using it (on Chrome and Firefox) for nearly 2 weeks without any problems.

smblott-github added a commit to smblott-github/vimium that referenced this pull request Aug 29, 2017
- Remove the low-level test which examines intividual modifier settings
  and replace it with a higher-level test which lists the relevant
  modes.  The previous test was hard to read.

- Expand the test to open *any* `href` (not just for `a` elements).  Can
  this do any harm?

Mention @mrmr1993.
@smblott-github
Copy link
Collaborator

What about like this, @mrmr1993? The test of the modifier keys looked too confusing to me.

@gdh1995
Copy link
Contributor

gdh1995 commented Aug 29, 2017

I think there may be some websites which don't call preventDefault for a mouse event on <a href="#">function...</a>, and neither do those on <a href="javascript:;">...</a>, so it's better to check link.getAttribute("href") not in ["", "#"] and "://" in link.href.

href="#" and herf="javascript:;" are often used to provide a underline for the link text and make an <a> tab-focusable.

@mrmr1993
Copy link
Contributor Author

Good call! I wondered about these, but assumed they would spawn a new window. I've certainly never come across a spec for it not.

@ivanruvalcaba
Copy link

Hi all,

I don't know if the following information is relevant but I have noticed that this functionality doesn't work properly if you change the user-agent (tested on my Firefox Nightly 57.0a1, Linux 64bits host). I am currently using the AgentX web extension for that. This happens when I replace the user-agent with Google Chrome on MS Windows, so if I have to use this functionality I must restore the user-agent to a default value.

Best regards.

@smblott-github
Copy link
Collaborator

this functionality doesn't work properly if you change the user-agent

That's a serious problem. Could we figure out the browser on the background page and then inform the front end when each frame registers?

@gdh1995
Copy link
Contributor

gdh1995 commented Sep 7, 2017

Why not check typeof browser === "object" && !!browser.runtime?

@mrmr1993
Copy link
Contributor Author

mrmr1993 commented Sep 7, 2017

Could we figure out the browser on the background page and then inform the front end when each frame registers?

Done. I've used a method which should be fairly future-proof and shouldn't break if/when Edge and Chrome adopt Mozilla's extension API additions.

@mrmr1993
Copy link
Contributor Author

mrmr1993 commented Sep 7, 2017

I think there may be some websites which don't call preventDefault for a mouse event on <a href="#">function...</a>, and neither do those on <a href="javascript:;">...</a>, so it's better to check link.getAttribute("href") not in ["", "#"] and "://" in link.href.

href="#" and herf="javascript:;" are often used to provide a underline for the link text and make an <a> tab-focusable.

@gdh1995 I've just done some testing on this. The current behaviour matches what clicking does with the relevant modifier keys (except for javascript: URLs, where Firefox won't let us open a tab). I don't think these are changes we should make.

@gdh1995
Copy link
Contributor

gdh1995 commented Sep 7, 2017

The current behaviour matches what clicking does with the relevant modifier keys

OKay.

And the new API runtime.getBrowserInfo does work. Good job!

@ghost
Copy link

ghost commented Sep 21, 2017

@mrmr1993 thanks for this fix! Thanks to it I can complete my switch from Chrome to Firefox without missing anything.
@philc Do you think that after fixing the merge-conflicts, this PR can be merged?

clickActivator = (modifiers) -> (link) ->
defaultActionsTriggered = DomUtils.simulateClick link, modifiers
simulateClickDefaultAction = Utils.isFirefox()
if simulateClickDefaultAction and
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrmr1993. We can merge this. But I'd really appreciate it if you could find a way of avoiding repeating the modifier/new-tab logic here. That logic rightly belongs -- in my opinion -- with the various modes at the top of this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about moving it into DomUtils.simulateClick? Since it's a workaround for that rather than specifically for link hints, there makes more sense to me.

I'll rebase and make the change -- whichever you choose -- in a little bit.

@mrmr1993 mrmr1993 force-pushed the ff-link-hints-new-tabs branch from e8649b9 to a8337e9 Compare September 21, 2017 19:39
@mrmr1993 mrmr1993 force-pushed the ff-link-hints-new-tabs branch from 315d5a1 to a8337e9 Compare September 21, 2017 20:54
@mrmr1993
Copy link
Contributor Author

I've rebased this, moved the fix code into DomUtils, (hopefully) made the code a bit clearer, and added an equivalent workaround for the shift key modifier.

@smblott-github smblott-github merged commit f0c90f3 into philc:master Sep 25, 2017
gdh1995 added a commit to gdh1995/vimium-c that referenced this pull request Apr 3, 2019
now simulate the default action to open a new tab during VHints.*.run if needed

merged:
* philc/vimium#2602
* philc/vimium#2681

differences:
* not deal with the case of "shift=true,others=false"
  * it's impossible during normal processes
* support <a rel~=noopener>
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 this pull request may close these issues.

5 participants