This is in Chrome at least. If my window's URL is https://www.google.com/search?q=JavaScript+URLSearchParams
and I run this in the JavaScript console:
url = new URL(document.URL);
urlsp = url.searchParams;
console.log(urlsp.get("q"));
then what gets logged to the console is not JavaScript+URLSearchParams
, but JavaScript URLSearchParams
. This is a pain because the userscript that I am trying to write needs access to the actual value of the q
parameter; and
+
are not treated the same by the browser. Sure, I could write some code that would process the URL as a string, but that would be tedious and error-prone. The same deal happens with the value %3A
in a parameter, but it gets returned as :
instead. How do I get URLSearchParams to return the actual value of a URL's parameter?