Commit 0e1fcaf4 authored by Mathias Bynens's avatar Mathias Bynens Committed by Commit Bot

Simplify getHost by using the URL constructor

This patch removes the dependency on a dynamically-generated anchor
element just to get the origin of a given string representing a URL.

Change-Id: I3fdc9416da768ca44f168622538af191093cd804
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2535051Reviewed-by: default avatarHenrik Grunell <grunell@chromium.org>
Commit-Queue: Mathias Bynens <mathias@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827743}
parent 9f22bfb4
......@@ -20,17 +20,8 @@ chrome.runtime.onMessageExternal.addListener(function(
if (!url) {
return '';
}
// Use the DOM to parse the URL. Since we don't add the anchor to
// the page, this is the only reference to it and it will be
// deleted once it's gone out of scope.
const a = document.createElement('a');
a.href = url;
let origin = a.protocol + '//' + a.hostname;
if (a.port != '') {
origin = origin + ':' + a.port;
}
origin = origin + '/';
return origin;
const origin = new URL(url).origin;
return `${origin}/`;
}
try {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment