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

Fix clickable elements with class 'btn' #4566

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

ScottWilliamAnderson
Copy link

@ScottWilliamAnderson ScottWilliamAnderson commented Oct 29, 2024

Fixes #3550

Update content_scripts/link_hints.js to make elements with class 'btn' clickable.

  • Add logic to getLocalHintsForElement to check for class 'btn' and mark elements as clickable.

For more details, open the Copilot Workspace session.

Fixes philc#3550

Update `content_scripts/link_hints.js` to make elements with class 'btn' clickable.

* Add logic to `getLocalHintsForElement` to check for class 'btn' and mark elements as clickable.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/philc/vimium/issues/3550?shareId=XXXX-XXXX-XXXX-XXXX).
@ScottWilliamAnderson ScottWilliamAnderson marked this pull request as ready for review October 29, 2024 10:03
Comment on lines 1216 to 1219
if (!isClickable && className?.toLowerCase().includes("btn")) {
isClickable = true;
possibleFalsePositive = true;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be part of the same if statement by doing something like:
if (!isClickable && (className?.toLowerCase().includes("button") || className?.toLowerCase().includes("btn")))

Choose a reason for hiding this comment

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

Agreed, I've made a change to address this.

…redundant check for class 'button'

* Merge the if statement for 'button' and 'btn' classes
* Remove redundant check for class 'button'
@ScottWilliamAnderson
Copy link
Author

@philc I think this PR is ready for review, let me know what you think

@philc
Copy link
Owner

philc commented Jan 4, 2025

Thanks for the PR. Link hint detection is the main hot/expensive path in Vimium, so we should carefully understand and introduce each change there. Can you provide a few examples of websites which use btn as the class name for elements which aren't already detected by Vimium?

// clickables are often wrapped in elements with such class names. So, when we find clickables
// based only on their class name, we mark them as unreliable.
const className = element.getAttribute("class");
if (!isClickable && className?.toLowerCase().includes("button")) {
if (!isClickable && (className?.toLowerCase().includes("button") || className?.toLowerCase().includes("btn"))) {
Copy link
Owner

@philc philc Jan 4, 2025

Choose a reason for hiding this comment

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

We should extract the className and call toLowerCase() on it only once rather than twice.

@ScottWilliamAnderson
Copy link
Author

Thanks for the PR. Link hint detection is the main hot/expensive path in Vimium, so we should carefully understand and introduce each change there. Can you provide a few examples of websites which use btn as the class name for elements which aren't already detected by Vimium?

Thanks Phil. I came across this when using the default bootstrap toggles during development:

https://getbootstrap.com/docs/5.3/forms/checks-radios/#toggle-buttons

How expensive is the detection, have you been able to profile it before?

@philc
Copy link
Owner

philc commented Jan 4, 2025

On the page you linked, I couldn't find the Bootstrap controls which aren't showing hints -- all of them (except the disabled ones) show hints. Was it for an older version of Bootstrap?

Benchmarking requirers running the link hint code on a page several times in a loop (see examples in #3063, #2410). I'm sure your change wouldn't be detectable in the runtime. The cost of this change is more about having more rules, and the documentation for why they're there, in a performance-critical part of the code.

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.

Make class="btn" clickable / Or support clickable css rule extention
3 participants