Issue with the URLSearchParams interface in content scripts

I noticed an issue when working with the [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("")
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?

BTW, this works just fine on Chrome.

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.

Right, so what I’m suggesting is to try and use just new URL instead of new window.URL.

Ah, got it. Yeah I tried that too - no change :neutral_face:

Then I have two more suspicions:

  1. it’s a bug with a polyfill you’re inadvertently injecting with your content script
  2. it’s a bug in Firefox, and thus you should be able to make a minimal extension (essentially just a content script) that reproduces the bug. If that is the case, please open a bug at with that sample extension as attachment.

Makes sense, I’ll check that out.