I noticed an issue when working with the [URLSearchParams](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) interface in the content script. I am trying to get hold of the keys in the “search” part of a URL.
This works when I try on the browser’s JS console. But when I do the same in the content script’s console, I get an error saying TypeError: obj.searchParams.keys(...) is not iterable.
See outputs below:
obj = new window.URL("https://www.somwebsite.com/show/3001C?name=asd")
keys = [...obj.searchParams.keys()]
// On a regular browser console => Array [ "name" ]
// On content script's console => TypeError: obj.searchParams.keys(...) is not iterable
Are there limitations on the URL and related APIs in the content script?
window.URL will use the URL constructor from the webpage, which should in theory be just as fine (since it’s X-Ray wrapped). However I wonder if something about the X-Ray wrapper breaks in this case. You should only need to use window.URL over URL if you want to pass the instance back to the page somehow.
See also
Thanks for the quick response @freaktechnik. I don’t need to pass anything back to the page script. All I need is get hold of the URL of the current page, extract the search params and take a decision based on the presence of a certain param.