March 18, 2010

GWT Development Mode Bookmarklet

Sometimes, when debugging a GWT application, one needs to attach the magical gwt.codesvr= incantation to a URL manually, for whatever reason. It’s easy enough to do this by hand but even easier to use a bookmarklet. Create a bookmark from that there link and, when you click it later, it will add the GWT development mode parameters to the currently open URL. If you need to use a development mode server other than localhost you’ll need to edit the bookmarklet accordingly – it may be easier to do so using the un-collapsed script:

javascript:(
  function() {
    h = "localhost";
    p = "9997";
    l = "gwt.codesvr=" + h + ":" + p;

    if (document.location.href.indexOf("gwt.codesvr") < 0) {
      q = document.location.href.indexOf("?");

      if (q < 0) {
        document.location.href = document.location.href + "?" + l;
      } else {
        b = document.location.href.substr(0, q + 1);
        e = document.location.href.substr(q + 1);
        document.location.href = b + l + "&" + e;
      }
    }
  }
)();