 
   urlParams = {}
   for kv in (location + '').replace(/^[^\?]*($|\?)/, '').split '&'
-    [_, k, v] = /^([^=]*)=?(.*)$/.exec kv; urlParams[unescape(k or '')] = unescape(v or '')
+    [_, k, v] = /^([^=]*)=?(.*)$/.exec kv; urlParams[unescape k || ''] = unescape v || ''
 
   do -> # restore window state:
     if D.floating

    return
  nww.show(); nww.focus() # focus() is needed for the Mac

  throttle = (f) -> tid = null; -> tid ?= setTimeout (-> f(); tid = null; return), 500; return
  saveWindowState = throttle ->
    posStr = JSON.stringify [
      nww.x      - (nww.dx || 0)

  gui = require 'nw.gui'; crypto = require 'crypto'; fs = require 'fs'; nomnom = require 'nomnom'
  path = require 'path'; {spawn} = require 'child_process'; proxy = require './proxy'

  segmOverlap = (a, b, c, d) -> a < d && c < b # Do the two segments ab and cd overlap?

  rectOverlap = (r0, r1) -> ( # A rectangle is {x,y,width,height}.  Do the two overlap?
    segmOverlap(r0.x, r0.x + r0.width,  r1.x, r1.x + r1.width) &&
    segmOverlap(r0.y, r0.y + r0.height, r1.y, r1.y + r1.height)
  )

  segmFit = (a, b, A, B) -> # Nudge and/or squeeze "ab" as necessary so it fits into "AB".
    if b - a > B - A then [A, B] else if a < A then [A, A + b - a] else if b > B then [B - b + a, B] else [a, b]

  rectFit = (r, R) -> # like segmFit but for for rectangles
    [x, x1] = segmFit r.x, r.x + r.width,  R.x, R.x + R.width
    [y, y1] = segmFit r.y, r.y + r.height, R.y, R.y + R.height
    {x, y, width: x1 - x, height: y1 - y}

  restoreWindow = (w, r) -> # w: NWJS window, r: rectangle
    # Find a screen that overlaps with "r" and fit "w" inside it:
    for scr in gui.Screen.screens when rectOverlap scr.work_area, r
      r = rectFit r, scr.work_area
      w.moveTo r.x, r.y; w.resizeTo r.width, r.height
      process.nextTick ->
        w.dx = w.x      - r.x
