User Tools

Site Tools


Google Chrome gestures

The Gestures for Chrome extension is designed to add mouse gesture support to Google Chrome. It's not well documented yet, but I put something on the previously blank dev wiki. I'll replicate that content here so I have it. By the way, my config is here.

Adding a custom gesture

You can add gestures that run arbitrary javascript by selecting the "Run script …" option. This lets you do just about anything you can script!

Developing the script is fairly straightforward. You can write your script in a text editor and copy/paste into the script box, and it will remove the newlines automatically. Then click out of the text box, switch tab to a test page, reload, and try your new gesture out.

To debug it, use the Javascript console with console.log().

To receive information about how and where your gesture was activated, use the arg parameter that your script is automatically passed. This parameter has four key members:

  • arg.action: Information about the action you scripted, including script name.
  • arg.config: Configuration of the Chrome Gesture extension itself
  • arg.event: The last MouseEvent that triggered this event.
  • arg.key: The gesture sequence written as a string, e.g. "LRDU".

The arg.event is useful for finding find what you gestured over, because it includes the srcElement member. Therefore, the tag the gesture was run over is arg.event.srcElement.

As an example, the following gesture will zoom in on an image:

var factor = Math.sqrt(2);
var grow = function(img){x=img.width; y=img.height; img.width = x*factor; img.height = y*factor; };
var e = arg.event.srcElement;
var a = e.getElementsByTagName("img");
for (var i=0; i < a.length; i++) {

Of course, your usual globals like window and document are also available, as shown in this "view source" gesture code:"view-source:" + document.URL,"_blank");
google_chrome_gestures.txt · Last modified: 2012/05/21 22:31 by tkbletsc