ninoseki/mitaka

[BUG] Extension does not select links correctly

opzch opened this issue · 4 comments

opzch commented

Describe the bug

Extension context menu displays an invalid link on the first try.

Steps to reproduce

  • select and right-click on a link on a page, and the extension selects the current page URL from the address bar instead of extracting the link from the selected text;
  • select one link, de-select, select and right-click another link, and the extension menu will show the previous one, so I have to repeat the last step again to make it select the correct link.

Expected behavior

The extension selects URL/domain correctly on the first try.

Actual behavior

The extension does not show the selected URL/domain, displays another link instead.

Screenshots

Firefox
firefox

Chrome
chrome-1

chrome-2

System Information:

  • OS: Windows 10 19044.1586 (21H2) x64

  • Browser: Chrome 99.0.4844.84, 96.0.4664.202

  • Mitaka version: Mitaka 0.90.1

  • Browser: Firefox 98.0-1, 91.7.1

  • Mitaka version: Mitaka 0.90.2

Additional context

Changing extension settings (enabling/disabling TLD validation/"refang"/searchers) doesn't affect this issue.

opzch commented

This didn't help unfortunately. The extension still selects wrong links even if reloaded upon opening each page.

I think I've partially identified the problem, or more specifically, two problems. And I had to alter the replication steps slightly to get the behavior described.

Replication was done using:

  • OS: Windows 10 19044.1826 (21H2) x64
  • Mitaka version: Mitaka 0.91.0
  • Browser: Firefox 102.0.1 (64-bit)
  • Browser: Chrome 103.0.5060.134 (Official Build) (64-bit)

I wasn't able to determine the website shown in the first screenshot, so all my testing was done on the phishtank (https://phishtank.org/) website shown in the second and third screenshots. The problems aren't absolutely specific to that website, but one problem is a result of the structure of that website and occurs on other websites with similar structures.

1: Extension selecting current page URL instead of highlighted URL

I don't believe the extension is selecting the page URL, or at least I wasn't able to replicate this behavior. However, I did notice that when selecting the URLs in the "Phish URL" column I would frequently find Mitaka parsing that URL as "detail.php".

For reference the relevant html on the page looks like this:

<tr>
  <td>
    <a href="phish_detail.php?phish_id=1234567">1234567</a>
  </td>

  <td>
    www.example.com
  </td>
</tr>

This seems to be due to an issue with text selection in general and not Mitaka specifically. I'm not sure if the selection behavior is controlled by the browser or the OS, there may be an OS or browser setting that can be change to correct this behavior.
Either way what appears to be happening is that when attempting to select "www.example.com" by dragging the selection, if the selection is dragged a bit too far it will also select the <a> tag in the preceding table cell. However, the visual indicator of the current selection does not properly expand to include the contents of the preceding table cell that is now part of the selection. Then Mitaka parses this by identifying the presence of an "href" attribute and selecting the value contained within.

Mitaka's behavior here is technically correct. It is being given input that differs from what is expected by the user and thus it is producing output that does not match the user's expectations.

Double clicking to select instead of dragging will correctly select "www.example.com". It is possible to select "www.example.com" via dragging, but the margin of error is extremely small. Dragging the selection past "www.example.com" by even a couple of pixels will result in the wrong selection.

This issue illuminates another potential problem with the extension, how to handle <a> tags with content that differs from the "href" attribute. For example, given the following html:

<a href="www.foo.com">www.bar.com</a>

Mitaka will use the value from the "href" attribute instead of the visible text - i.e. instead of parsing "www.bar.com", Mitaka will parse "www.foo.com". I'm not sure what the best method to resolve this is, as the current behavior is favorable in some situations and unfavorable in others.
Probably the best solution is to simply explain this behavior in the "Common Questions" section of the readme.
Or alternatively, provide an option in the extension's configuration page to enable or disable parsing "href" values if there is a difference between a given <a> tag's content and its "href" value.

2: Extension menu showing previous selection

This seems to be caused by Mitaka not properly recreating the context menu on a new selection. I was able to replicate this issue by:

  1. Select some text in window/tab 1.
  2. Change the active window or tab (window/tab 2).
  3. Select some text in window/tab 2.
  4. Change the active window or tab back to window/tab 1.
  5. Open the context menu for the text selected in step 1.
  6. Mitaka will use the selection from window/tab 2 instead of the selection from window/tab 1.

I'm not sure exactly what is preventing the context menu from properly updating, but I will continue looking into it.

  1. Yes href value of a tag has higher priority than a tag’s text in the current implementation. But I agree it may not intuitive. So I will add an option to change the behavior.

  2. It’s a known issue. Mitaka does a little bit CPU heavy task and it causes a such glitch sometimes. Let me know if you figure out a good solution for that.