getEventSourceUrl = function getEventSourceUrl(event) {
  var frames = _toConsumableArray(document.querySelectorAll('iframe[data-is-storybook]')); // try to find the originating iframe by matching it's contentWindow
  // This might not be cross-origin safe


  var _frames$filter = frames.filter(function (element) {
    try {
      return element.contentWindow === event.source;
    } catch (err) {// continue
    }

    var src = element.getAttribute('src');
    var origin;

    try {
      var _URL = new URL(src, document.location);

      origin = _URL.origin;
    } catch (err) {
      return false;
    }

    return origin === event.origin;
  }),
      _frames$filter2 = _toArray(_frames$filter),
      frame = _frames$filter2[0],
      remainder = _frames$filter2.slice(1);

  if (frame && remainder.length === 0) {
    var src = frame.getAttribute('src');

    var _URL2 = new URL(src, document.location),
        protocol = _URL2.protocol,
        host = _URL2.host,
        pathname = _URL2.pathname;

    return "".concat(protocol, "//").concat(host).concat(pathname);
  }

  if (remainder.length > 0) {
    // If we found multiple matches, there's going to be trouble
    _storybook_client_logger__WEBPACK_IMPORTED_MODULE_30__[/* logger */ "a"].error('found multiple candidates for event source');
  } // If we found no frames of matches


  return null;
}
Sends `event` to the associated window. If the window does not yet exist
the event will be stored in a buffer and sent when the window exists.
@param event