david-tejada / rango

🦎 The cross browser extension that helps you control your browser by voice. It blends in!
MIT License
121 stars 15 forks source link

Rango

✨ rango.click ✨
The cross browser extension that helps you control your browser by voice.
🦎 It blends in!

Introduction

Rango is a cross browser extension that helps you interact with web pages using your voice and talon. It does this by drawing hints with letters next to elements that you can use to click, hover, copy or show link adresses. It also helps you scroll, open multiple links in new tabs, close multiple tabs and more.

Sponsorship

Rango is mostly the work of one developer. I have spent hundreds of hours making sure Rango works and feels great. I would like to be able to continue working on Rango to make it even better. To be able to do that I need your support. If Rango makes your life easier when navigating the web or it has become an essential tool for you, please consider becoming a sponsor. Click here or just say rango open sponsor.

Support

If you have any question or need help, you can reach out in the channel #ext-rango of the Talon Slack.

Installation

In order to use the extension you need two pieces: the extension and the talon files.

It is also assumed that you have installed talonhub/community to your talon user folder. If not you need at least to have the following captures defined: <user.letter>, <user.word>, <user.number_small>, <user.number_string> (only if you want to use number hints) and the list {user.website}.

IMPORTANT: Disabling Rango on Some Browsers

Once rango-talon has been added to your talon user folder, Rango will be active for all your browsers. If you haven't installed the extension itself in a specific browser, it's better to disable Rango for that browser to avoid unexpected behavior. The best way to do this is to activate the tag user.rango_disabled for that browser. For example, if you want to disable Rango in Brave and Chrome, you could have a .talon file with the following contents anywhere in your talon user folder.

app: brave
app: chrome
-
tag(): user.rango_disabled

Troubleshooting

Commands Don't Work

If the hints are displayed but the commands don't work, most of the time it has to do with the configuration of the hotkey. In order to communicate with Rango, Talon presses a key combination to prompt Rango to read the command present on the clipboard. By default the key combination is ctrl-shift-insert in all the browsers except for Safari, where it is ctrl-shift-3. If Rango commands aren't working for you, make sure that the hotkey is properly set up. The shortcut that needs to be changed is Get the talon request.

Where to Find the Extension Keyboard Shortcuts

In Firefox, navigate to about:addons, click on the cog at the top right and then "Manage Extension Shortcuts".

In Chrome, navigate to chrome://extensions/shortcuts.

In Edge, navigate to edge://extensions/shortcuts.

No Hints Viewing Local Files

In order for Rango to work within local files like file:///Users/david/Code/my-page/index.html when using a Chromium browser you will have to enable it. Navigate to the extension details and enable the setting Allow access to file URLs.

In Firefox access to file URLs is always enabled.

Unfortunately, Safari doesn't allow extensions to access file URLs at all, so this feature won't be available in this browser.

Settings

There are several settings you can adjust to change the appearance of the hints and the overall behavior of the extension. To open the settings page you just need to use the command rango settings. You can also open them by right clicking the extension icon and clicking the menu item Settings.

Usage

Note: The notation <target> in this readme can refer to a single or multiple hints chained with the word and (or the word plus if you use number hints). For example, the command click any and bat would click on the elements marked with the hints a and b. Most Rango commands accept multiple hints as target.

Hints

Hints are marks with letters (or numbers if you toggle the setting Use number for hints) that appear next to elements and that we can use to refer to the element to click, hover, copy its text content, etc.

If you want to know how to use number for hints, which elements receive hints and what to do if an element you want to click doesn't have a hint, take a look at the section More on hints.

Click

There are two modes: direct and explicit clicking. By default direct mode is enabled. To use explicit clicking you need to delete the tag user.rango_direct_clicking in rango.talon.

Direct Clicking

This is the default mode. With it enabled you just have to say the characters displayed on the hint to click an element. To avoid misclicks it only listens to a pause, one or two letters, followed by another pause. If there is no hint with those letters it will type them. If you actually want to enter one or two characters the are part of a hint you have to use the talonhub/community command press.

Examples

Explicit Clicking

With explicit clicking you have to precede every hint with the word click. This mode prevents any misclicks at the expense of being a bit more tedious.

Keyboard Clicking

Apart from using your voice for clicking you can also use your keyboard for that.

To toggle it you have to use the command keyboard toggle or press ctrl-shift-5 in Firefox. In Chrome and Edge you have to set the shortcut manually since there is a limit of four shortcuts we can set by default. You'll see the toolbar icon shows a little orange dot when keyboard clicking is on. To allow typing text in pages, keyboard clicking will be off whenever the element in focus accepts text input.

Excluding Keys

When using keyboard clicking you might want to have the ability to use certain keys as shortcuts for specific websites. For example, you might want to be able to use the key c in YouTube to toggle captions. The easy way to do this is to right click on the extension icon and select the menu Add Keys to Exclude. This will add an entry to the keys to exclude setting with the URL pattern for the current URL and will open the settings so you can easily add the keys you want to exclude.

Focus

Focus and Enter

Clicking with Rango might fail on some elements. For example, clicking on elements that copy things to the clipboard almost always fails because the browser thinks there was no user interaction and disallows it. To avoid this pitfall you might use the following command.

Open in a New Tab

Navigation

Input Fields

Note: "Input field" here refers to any element with editable content. It doesn't need to be an <input> element.

Copy to the Clipboard

Copy Current URL Information

Hover

Show Element Information

Scroll

The default behavior for scrolling in Rango is "smooth". The behavior will be "instant" if you have configured your OS to prefer reduced motion. You can follow the instructions here if you want to know how to do that. You can also configure the preferred scrolling behavior in the settings.

Page Scrolling

These commands scroll the page, that is, the html or body elements, or the scroll container at the center of the page if those elements don't scroll.

Aside Scrolling

You can easily scroll the left or right aside with these commands:

Scrolling the Container That Includes a Hinted Element

Sometimes we want to scroll a container that is not the main page or an aside. An example for that could be a popup with links. For that we need to refer to one of the hints inside said container and use one of the following commands:

Scrolling the Same Container Repeated Times

Once you have scrolled a container by referring to a hint inside it, you can keep scrolling the same container with these commands without needing to refer to a hint within it again. It will also use the same amount of scroll last used:

Scrolling an Element to the Top, Bottom or Center

Custom Scroll Amounts

You can change the scroll amount of these commands or create new scroll commands by adding/changing the last argument in the action call in your rango.talon file. For example, the next commands would scroll up or down half of its scroll container:

half up: user.rango_command_without_target("scrollUpPage", 0.5)
half down: user.rango_command_without_target("scrollDownPage", 0.5)
half up <user.rango_target>:
  user.rango_command_with_target("scrollUpAtElement", rango_target, 0.5)
half down <user.rango_target>:
  user.rango_command_with_target("scrollDownAtElement", rango_target, 0.5)

Save Scroll Positions

You can save scroll positions within a webpage to later be able to scroll to that saved position.

Tabs

Close Tabs

Focus Tabs Using Tab Markers

If you have the setting Include tab markers in title enabled (default) you can refer to those markers to quickly focus a specific tab.

Custom References

Custom references are a way to store references to hints and their underlying element for later use either directly or in scripting. Once created references will work even when the hints are off.

Save References

Use References Directly

Use References in Scripting

In order to use the saved references in scripting you need to use the talon action user.rango_run_action_on_reference. This action accept two arguments: the name of the action and the name of the reference.

Following is a simple example of a command that clicks the element with the reference edit:

edit this: user.rango_run_action_on_reference("clickElement", "edit")

There are also a few talon helpers that will make easier to create commands that use references. These will be active when editing .talon files.

Fuzzy Search Elements

Similar to custom references you can also target elements by their text content using fuzzy search. This can also be used for scripting purposes with the advantage that there is no need to previously save a reference to the element.

Using Fuzzy Search Directly to Run Actions on Elements

Scripting Using Fuzzy Search

In order to use fuzzy search in scripting you need to use the talon action user.rango_run_action_on_text_matched_element. This action accepts three arguments: the name of the action, the text searched and whether to prioritize elements within the viewport or not (optional, defaults to false).

Following is a simple example of a command that clicks the element that better matches the text "edit" anywhere in the document.

edit this: user.rango_run_action_on_text_matched_element("clickElement", "edit", false)

There are also a few talon helpers that will make easier to create commands using fuzzy search. These will be active when editing .talon files.

Modify Hints Size

Show and Hide the Hints

Other ways to toggle the hints on and off

Opening Rango Related Pages

More on Hints

Using Number for Hints

If you prefer to use numbers instead of letters for hints there are two steps you need to take:

One thing to consider is that Rango draws hints outside of the viewport for a better scrolling experience. When using number hints this might often result in three digit numbers being used. These high numbers might be longer to pronounce. If you want to minimize this you can modify the margin around the viewport where Rango draws hints. For that you can use the setting Viewport margin. A value of 0 will make that only the elements within the viewport receive hints.

Which Elements Receive Hints

By default, only certain elements receive hints. If the element is clickable it should receive a hint. Most of the time it does, but in some rare cases, it might not. In order for an element to receive a hint it must be minimally accessible. This means that it must use the right semantic element or indicate what its role is. For example, the following buttons would display a hint.

<button>Click me!</button>

<div role="button">Click me!</div>

But there won't be a hint for the following element:

<div class="btn">Click me!</div>

In earlier versions of the extension I would try to display more hints by default by looking at things like the element's class name, the onclick property or the css property cursor: pointer. The issue with this approach is we would get many duplicate hints and some unnecessary ones. Reducing those duplicates and unnecessary hints wasn't always possible and resulted in complicated and poorly performant code.

Displaying Extra Hints

Moving away from that complicated logic resulted in better performance and cleaner ui. But now we need a way to display hints for those elements that are not accessible. For that we use the command hint extra. At this point we don't care so much about duplicates and we can use all those extra checks to see if an element might be clickable. The command hint less lets us go back to only displaying the default hints.

Custom Hints

With the command hint extra now we have a way to show hints for those elements that don't receive them by default. But you might frequently use some page where some elements that you want to click don't receive hints. Having to use the command hint extra every time you want to click one of those elements can become tedious. Custom hints are a way to indicate that you want some extra hints to always display by default.

After having used the command hint extra you can use the command include <target> to indicate that you want some hints to always display. The hints selected for inclusion will be marked in green. The best approach is to use at least a couple of hints representing the same ui element. With those hints Rango calculates the css selector that includes both. It tries not to be greedy and use the selector that includes the least amount of hints possible. This is usually enough to include the desired ui element. In case it falls short and doesn't include all the elements you want, you can use the command some more. This will pick a different selector that matches more elements (not necessarily the same elements matched before). The command some less does the opposite. You can use the include command again if you need to add more hints representing different ui elements. Once you are happy with the result you can use the command custom hints save so that those hints appear by default the next time.

If you want to exclude all the hints to later add only the ones you're interested in you can use the command exclude all. You will need to save after using this command and before including only those hints you want.

Here is one example to illustrate this process:

In this page we have this section which unfortunately doesn't show any hints.

Now we use the command hint extra to greedily display hints.

If we wanted to show hints for the gray links we can issue the command include cap each and cap drum, which marks in green the hints that will be included.

Since the result is not exactly what we want and there are still hints missing we use the command some more.

Now there are more hints showing but they're not the ones we want. We issue the command some more again to see if that helps.

The hints marked for inclusion now are exactly the ones we want. We could continue including more custom hints using the include command again but for the moment we leave it like that and save with custom hints save.

Now the extra hints disappear and we are left with the custom hints that we just defined. We can see that similar elements also display hints. Next time we visit the page those hints will be displayed by default.

This same process can be used to exclude hints using the command exclude <target>. With the command hint more we can display any previously excluded hints.

If after using the include or exclude command you are not happy with the hints marked for inclusion/exclusion you can use the command some less (you might have to use it a few times if you've already used the command some more) to remove the recently marked hints and start over. This will keep any hints marked with a previous include or exclude command.

Here is a summary of all the commands for customizing hints:

Custom hints can also be edited, added or removed from the settings page.

Hiding a Particular Hint

On occasions a hint might be obscured by another hint that is stacked on top of the first one. For those occasions you can use the command hide <target> to hide the hint on top.

Known Issues and Limitations

There is currently no way to open a pure CSS dropdown menu like the "hover" menu in this example. It is not possible to activate the :hover pseudo class in javascript and this will only be possible once I implement cursor moving/clicking.

No Hints or Other Missing Functionality in Certain Pages

Content scripts (the part of the extension that runs in the context of webpages) aren't able to run in browser's internal pages. These pages start with chrome://, edge://, about: or similar and provide information and control over browsers internal state, including settings, flags, and debugging information. Allowing content scripts on these pages could enable malicious extensions to change settings or access sensitive data without the user's knowledge. For this reason hints an other functionality won't be available in these pages.

Similarly, there are other domains where content scripts are not allowed to run.

These are restricted Chromium domains:

clients.google.com
clients[0-9]+.google.com
sb-ssl.google.com
chrome.google.com/webstore/*

These are restricted Firefox domains:

accounts-static.cdn.mozilla.net
accounts.firefox.com
addons.cdn.mozilla.net
addons.mozilla.org
api.accounts.firefox.com
content.cdn.mozilla.net
discovery.addons.mozilla.org
install.mozilla.org
oauth.accounts.firefox.com
profile.accounts.firefox.com
support.mozilla.org
sync.services.mozilla.com

To allow WebExtensions in Firefox to run on these pages (at your own risk), open about:config and modify the following[^3]:

Another alternative is to use a Chromium browser to access Firefox restricted domains and Firefox to access Chromium restricted domains.

[^3]: https://www.ghacks.net/2017/10/27/how-to-enable-firefox-webextensions-on-mozilla-websites/

Contributing

See the Contributing guide.