function getActiveElement(doc) /*?DOMElement*/{
  doc = doc || (typeof document !== 'undefined' ? document : undefined);
  if (typeof doc === 'undefined') {
    return null;
  }
  try {
    return doc.activeElement || doc.body;
  } catch (e) {
    return doc.body;
  }
}
Same as document.activeElement but wraps in a try-catch block. In IE it is
not safe to call document.activeElement if there is nothing focused.

The activeElement will be null only if the document or document body is not
yet defined.

@param {?DOMDocument} doc Defaults to current document.
@return {?DOMElement}