We're hiring!

We're actively seeking designers and developers for our all three of our locations.

Auto Login During Development with dotjs

dotjs is a browser extension that executes domain-specific JavaScript files stored in your Home directory (in the ~/.js subdirectory). It came out last year as a Mac OS X specific Chrome extension and has since been ported to Firefox, Safari, Windows, and Linux.

Very conveniently, all dotjs scripts automatically have jQuery 1.6.2 loaded for you to use, which makes it incredibly easy to put together a quick script for some change/enhancement you might want to make to any site. And with extensions now available for all of the browsers I use, I can write a single script that is stored in one place and is executed regardless of which browser I am using.

The possibilities for what to do with a dotjs script are endless. One of my favorite ways of using it is to write a script that automatically logs me in to whatever application I am currently developing on my laptop. This is especially useful when working on a site that has a very short timeout period, or one that forces you to log in again every time the application is restarted.

dotjs looks for user scripts based on the domain name of the site you are viewing. From the README:

On subdomains such as http://gist.github.com dotjs will try to load ~/.js/gist.github.com.js as well as ~/.js/github.com.js and ~/.js/com.js.

This means a ~/.js/localhost.js script will be loaded and executed while I am navigating an application being served on my local machine. If you are using something like pow (or even just adding entries to your /etc/hosts file) you can have separate dotjs scripts for each of your local development domains as well.

The following is an example of a simple dotjs localhost.js script I have been using to automatically log me in whenever I end up on the login page.

  if (/^\/login\/auth/.test(window.location.pathname)) {
    $('#username').val("dev");
    $('#password').val("devpassword");
    $('#sign-in').click();
  }

The first line checks the current path to make sure it only executes on the login page. The rest is just straight jQuery to fill in the fields and click the submit button.

My favorite thing about how dotjs works is that it picks up changes immediately, in all of the browsers it is installed on. If I don’t want to be logged in automatically (perhaps I am working on styling the login page) or I want to be logged in as a different user, I can just update the script — and the very next time I hit the login page, I get the behavior I want.

If you haven’t tried user scripting with dotjs yet, I highly recommend that you do.

Patrick Bacon (46 Posts)

I’m a software developer at Atomic Object (since 2005) in Grand Rapids, MI.

This entry was posted in Web Apps and tagged . Bookmark the permalink. Both comments and trackbacks are currently closed.

One Comment

  1. Posted October 9, 2012 at 6:20 am

    Dotjs was originally created by Chris Wanstrath as a Google Chrome extension.dotjs compares the url of the page to a list of files on the filesystem.you provide login code can help it to the developers.