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?
%20not+. Javascript's encode function incorrectly changes all spaces to%20. In the param part of the URL though,+are considered spaces. Also, @Melab,Javascript+URLSearchParamsis NOT the value. That is the encoded value. The actual value is correctlyJavaScript URLSearchParams.encodeURIComponentwill fix other characters like %3A, just do it after you fix the spaces.encodeURIComponent(urlsp.get("q"))does not do that.+but that's not the value, that's its encoded value. stackoverflow.com/questions/1634271/…. The problem is you are oddly trying to process an encoded value instead of the actual value. You say you want the value, but you are actually trying to get an ENCODED value.