urlParseWithCommonChecks = function(urlStr) {
  let res;
  try {
    res = new NATIVE_URL(urlStr);
  } catch (e) {
    throw new Error(`${urlStr} is not a valid URL.`);
  }
  const canonicalPort = canonicalPortForProtocols.get(res.protocol);
  if (!canonicalPort) {
    throw new Error(`${urlStr} is not a valid URL.`);
  }
  if (!res.hostname) {
    throw new Error(`${urlStr} is not a valid URL.`);
  }
  // For some protocols, Edge doen't know how to construct the origin.
  if (res.origin != 'null') {
    return res;
  }
  // We can't assign to the native object's origin property (it is ignored), so
  // we make a copy here.
  const urlLike = {
    href: res.href,
    protocol: res.protocol,
    username: '',
    password: '',
    host: res.host,
    port: res.port,
    // origin assigned below after canonicalization.
    hostname: res.hostname,
    pathname: res.pathname,
    search: res.search,
    // We don't copy searchParams because Edge doesn't have it anyways.
    hash: res.hash,
  };
  if (canonicalPort === res.port) {
    // This does not work for blob and file protocol types - they are far more
    // complicated.
    urlLike.origin = res.protocol + '//' + res.hostname;
  } else {
    urlLike.origin = res.protocol + '//' + res.hostname + ':' + res.port;
  }
  return urlLike;
}
This function wraps 'new URL(href)' in newer browsers adds common checks for
parts of the URL spec (e.g. no protocol, no hostname for well-known protocols
like HTTP(s) and WS(S)) that some browsers don't adhere to. It also adds
origin construction for browsers that don't support it (Edge).
@param {string} urlStr
@return {!UrlLike}