vimium-c icon indicating copy to clipboard operation
vimium-c copied to clipboard

LinkHints.unhoverLast doesn't work in this situation

Open zyf0330 opened this issue 3 years ago • 3 comments

Describe the bug

An a element has two event listener onmouseenter and onmouseover, they produces two different effects. But vimium-c LinkHints.unhoverLast just cancels onmouseenter effect but not onmouseover effect.

To Reproduce

Steps to reproduce the behavior:

This is a paid website, so maybe I cannot produce.

Browser, OS and Vimium C versions

  • Browser name: Chrome
  • Browser version: Version 105.0.5195.125 (Official Build) (64-bit)
  • Vimium C version: Vimium C 1.99.3, Google Chrome 105, Linux.
  • OS name and version: Ubuntu 22.04

Extra infos If I execute below code, both two effects are canceled.

var event = new MouseEvent('mouseleave', 
       {view: window, bubbles: true, cancelable: true});

  var cancelled = !aElement.dispatchEvent(event);

zyf0330 avatar Sep 23 '22 09:09 zyf0330

Vimium C dispatches mouseout (bubbles: true, cancelable: true) and then mouseleave (bubbles: false, cancelable: false) in order, and this order has been used by Chrome for years and is still correct on Chrome 106. So there're such potential reasons of this issue:

  1. the website binds mouseleave listeners in a child element, but LinkHints in Vimium C trends to select a parent element, and then the listener was not triggered
  2. maybe the website's effects can not work well if mouseout and mouseleave are simulated by Vimium C in a same "macro task".

gdh1995 avatar Oct 06 '22 10:10 gdh1995

Vimium C's another command, named dispatchEvent, can be used to work around this compatibility issue:

Oh the correct mapping is:

map <v-dem> dispatchEvent direct="clicked" class="mouse"
run xxx dem#type=mouseout+dem#type=mouseleave&bubbles=false&cancelable=false

Added: syntax of run: https://github.com/gdh1995/vimium-c/wiki/Auto-run-a-tree-of-commands

gdh1995 avatar Oct 06 '22 10:10 gdh1995

Thank you. Is there doc about dispatchEvent? I don't understand what direct and class options mean.

zyf0330 avatar Oct 08 '22 03:10 zyf0330

Um, basically:

  1. the command is to create a simulated "event" object and "dispatch" it using browser's dispatchEvent API (https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/dispatchEvent);
  2. class means the "class type" of an event instance to be "dispatched", like keyboard for KeyboardEvent and mouse for MouseEvent;
  3. type is just the type member of a JS Event instance
  4. other common properties are passed to the MouseEvent constructor as options (https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent)

There's no document but only source code:

  • entry point of dispatchEvent: https://github.com/gdh1995/vimium-c/blob/68b4f58c092c806d79fb4461bd29c11aa5beb461/background/all_commands.ts#L188
  • class: https://github.com/gdh1995/vimium-c/blob/68b4f58c092c806d79fb4461bd29c11aa5beb461/background/all_commands.ts#L193
  • direct: https://github.com/gdh1995/vimium-c/blob/68b4f58c092c806d79fb4461bd29c11aa5beb461/content/link_hints.ts#L548

gdh1995 avatar Oct 10 '22 03:10 gdh1995

This is worked for me.

map <v-dem> dispatchEvent direct="clicked" class="mouse"
run Q dem#type=mouseout+dem#type=mouseleave&bubbles=true&cancelable=true

zyf0330 avatar Oct 10 '22 08:10 zyf0330

So does your test page require bubbles=true? But mouseleave should not have a bubbles of true, as far as I've tested on recent versions of Chrome and Firefox on Win11.

gdh1995 avatar Oct 10 '22 14:10 gdh1995

Sorry, I just try and pick first successful expression. After some tries, I find run Q dem#type=mouseout+dem#type=mouseleave&cancelable=false just works which remove bubbles=false

zyf0330 avatar Oct 11 '22 02:10 zyf0330

Hello, v1.99.90 has been released on Chrome Web Store, and its LinkHints.unhoverLast (also also dispatchEvent) supports a parameter of bubbles=true:

map xxx LinkHints.unhoverLast bubbles

And you may take a try.

gdh1995 avatar Nov 23 '22 06:11 gdh1995

@gdh1995 This works perfectly. Thanks for your work.

zyf0330 avatar Nov 23 '22 07:11 zyf0330