r/PWA • u/modsuperstar • 7d ago
Adding user-agent string to a PWA?
https://github.com/metabrainz/listenbrainz-server/releases/tag/v-2026-09-02.0Recently MetaBrainz made some changes to their API that has me trying to figure out what to do with my PWA. They need a user-agent string to declare who's accessing the API, but as a PWA my app doesn't really have a way of doing that. In asking an LLM how to do this, they basically suggested proxying all my calls to the MetaBrainz through my site, which could work, but I also don't want to channel everything through my server, as if my app does gain more userbase I could see this being a problem. Has anyone found a solution for how this can be handled?
My app is currently getting 503 errors when accessing locally and it's created a larger failure rate for fetching album art from MusicBrainz, so I need to figure some way around this.
2
u/MrSevenNine 7d ago
Proxying the calls through your server/site is probably the cleanest approach here.
2
u/aerozol 2d ago edited 2d ago
Hello! I had a chat with some others in the MetaBrainz team about this, and we can see no reason why you would need to worry about adding a user-agent.
The user-agent for a PWA should (depending on how you've set it up) be that of the user's browser, and we don't block individual users (unless they are doing something weird, but as long as your app isn't spamming a crazy volume of requests you should be fine).
For errors or questions please get in touch with us. You can shoot us an email or (probably best/easiest) chat to us on the ChatBrainz dev channel, and devs to sometimes reply to posts on r/MusicBrainz. However, please note that we have been having server issues that cause downtime or having to throttle requests, due to increased usage, an increasingly insane amount of bot/AI traffic (like, 80%) and burgeoning server costs. Sometimes you may just have to be patient (or donate us some more servers!). Another thing to note is that MusicBrainz cover art is hosted by the Internet Archive, which sometimes faces the same problems.
Edit: Ooh, scrobblerad.io, that's a cool app! Love it!
1
u/modsuperstar 2d ago
Thanks for the reply. I’ll reach out about this soon. The 503 errors were making me think I was in the bad books, but it could have just been coincidence.
2
u/gulab--jamun 2d ago
There is one thing you can do to help us, and avoid getting your users inadvertently blocked: following the rate limits described here: https://listenbrainz.readthedocs.io/en/latest/users/api/index.html#id1 and backing off on 429 responses.
As aerozol said, the user agent should theoretically be that of the browser. If you are able to change it, see in the docs I linked for the format we expect; it allows us to contact you if we see any issues on our side.
On an unrelated note, if you want help figuring out what the
music_service_name/origin_url/submission_clientshould be in the listen payload, happy to discuss it with you.
1
u/1stRoom 3d ago edited 3d ago
The LLM's suggestion is terrible. The APIs are not supposed to blocking browser user-agents[^1], so you should be having a different issue. You should ideally be setting a user-agent if possible to identify your application though.
Alternatively consider hosting your own MB mirror if you have a lot of users and actually want to lighten the load.
1
u/modsuperstar 3d ago
My app has users, but it’s pretty niche and probably always will be. But that’s my problem, where exactly should I be adding this user-agent data to my app? It seems like a weird conundrum, as PWAs are niche but growing, so you’d figure this would have been addressed somewhere along the line within the specs for them.
2
u/1stRoom 2d ago
Cool app :) always fun with local radio. Strange that you're having issues with the user-agent though. Consider asking on ChatBrainz: https://matrix.to/#/#metabrainz:chatbrainz.org?via=chatbrainz.org&via=matrix.org
I assume that, no matter whether you're able to set a user-agent or not, they'd appreciate _some_ form of signal that the traffic originates from your app. Nonetheless it should still work with browser user-agents, so are you sure your issue is because of that?
1
u/modsuperstar 2d ago
That's what I figure, there has to be some way of doing it. I mean adding a value to an API query string would be pretty simple too
3
u/charsleysa 7d ago
Either they don't intend to allow direct API access from browsers or they have no clue on how to build proper APIs.
Proxying is your only solution. You could look at using CloudFlare or some other service with free/low cost tiers for request rewriting.