How can I get User Agent before any web request?

I’m developing a WebExtension. I know that when a web request is made, I can get User Agent with webRequest.onBeforeSendHeaders. However, I would like to get User Agent before any web request is made, because I want to fetch a JSON file, during loading of my WebExtension, based on the User Agent. Is that possible?

window.navigator.userAgent?

Yes, of course, I’m so stupid. I thought that navigator.userAgent would only apply to client-side JavaScript, so I never bothered to test it…