function getFrames(element, baseWindow) {
    var frames = [], curElement = element, doc, win;
    baseWindow = baseWindow || window;
    while (true) {
      if (!(doc = curElement.ownerDocument)) {
        console.error('Cannot get document that contains the element.');
        return null;
      }
      if (!(win = doc.defaultView)) {
        console.error('Cannot get window that contains the element.');
        return null;
      }
      if (win === baseWindow) { break; }
      if (!(curElement = win.frameElement)) {
        console.error('`baseWindow` was not found.'); // top-level window
        return null;
      }
      frames.unshift(curElement);
    }
    return frames;
  }
Get `<iframe>` elements in path to an element.
@param {Element} element - Target element.
@param {Window} [baseWindow] - Start searching at this window. This is excluded from result.
@returns {(Element[]|null)} An array of `<iframe>` elements or null when `baseWindow` was not found in the path.