445

alt textCaption

Web dev: What browser is visiting the page?

User agent string:

A screenshot of a browser. The URL bar reads firefox://settings, a button on the URL bar is labelled Netscape, a popup from the button reads: "You're viewing a secure Opera page", and the web page title reads "Chrome settings".

top 35 comments
sorted by: hot top controversial new old
[-] apprehentice@lemmy.enchanted.social 128 points 3 weeks ago

Functionally useless. With the web standardized, we shouldn't need user agents anyway. It would be more beneficial to ask "do you support X, Y, and Z?"

[-] Maestro@fedia.io 38 points 3 weeks ago

It's called feature detection and it goes a long way back, even before Modernizr popularized it.

[-] GammaGames@beehaw.org 7 points 3 weeks ago

Popularized? That gets less than 100k downloads a week

[-] dan@upvote.au 13 points 3 weeks ago* (last edited 3 weeks ago)

Most developers just write their own feature checks (a lot of detections are just a single line of code) or use a library that polyfills the feature if it's missing.

The person you're replying to is right, though. Modernizr popularized this approach. It predates npm, and npm still isn't their main distribution method, so the npm download numbers don't mean anything.

[-] GammaGames@beehaw.org 3 points 3 weeks ago

Neat, thanks for clarifying! I’ve never heard of it

It used to be huge.

[-] dan@upvote.au 22 points 3 weeks ago

That's exactly what you're supposed to do with the modern web, via feature detection and client hints.

The user agent in Chrome (and I think Firefox too) is "frozen" now, meaning it no longer receives any major updates.

[-] Quacksalber@sh.itjust.works 21 points 3 weeks ago

Youtube currently (for weeks now) does not work on Firefox, if you don't use a Firefox user agent. Google doing sketchy things again.

[-] KairuByte@lemmy.dbzer0.com 34 points 3 weeks ago

I’ve not run into this issue and use Firefox exclusively with ublock origin

[-] Quacksalber@sh.itjust.works 3 points 3 weeks ago

I use Charmeleon, with the effects described above.

[-] Carighan@lemmy.world 4 points 3 weeks ago* (last edited 3 weeks ago)

So you don't use Firefox, you mess with Firefox. That's on you then. Devs can't be held responsible for you intentionally breaking things. Only do what you know works.

[-] tyler@programming.dev 18 points 3 weeks ago

YouTube works fine on Firefox…

[-] Carighan@lemmy.world 8 points 3 weeks ago
[-] Quacksalber@sh.itjust.works 2 points 3 weeks ago

What works? YT on Firefox or YT on Firefox when the user agent is changed?

[-] Carighan@lemmy.world 6 points 3 weeks ago

Both. I use YT on Firefox constantly, and I just explicitly tried again with a swapped user agent, and there's no issues at all, works perfectly as expected. I saw from your other reply that you use a fairly involved and heavily modifying expansion, not just a user agent switcher.

If you try to "harden" your FF, always keep in mind that a large portion of that means absolutely breaking things left and right and center. It might work, but always expect it will not. Because it's just not something anybody would ever test for when creating web pages. So you're running essentially unknown scenarios. It might be interesting input to the extension-author that this breaks, though. It might be something they think they got working. Of course, it could also be that it's "Yeah that happens, it's intentional". But might as well report it to them.

[-] RustyNova@lemmy.world 3 points 3 weeks ago

Uh... I use librewolf that force a chrome + windows user agent and its totally fine?

[-] Quacksalber@sh.itjust.works 1 points 3 weeks ago

Then charmeleon must change more than just the user agent

[-] HeyThisIsntTheYMCA@lemmy.world 1 points 3 weeks ago

? I just tested and it worked fine.

[-] Boomkop3@reddthat.com 1 points 2 weeks ago

again? Did they stop anytime recently?

[-] elrik@lemmy.world 16 points 3 weeks ago

User agents are useful for checking if the request was made by a (legitimate self-identifying) bot, such as Googlebot.

It could also be used in some specific scenarios where you control the client and want to easily identify your client traffic in request logs.

Or maybe you offer a download on your site and you want to reorder your list to highlight the most likely correct binary for the platform in the user agent.

There are plenty of reasonable uses for user agent that have nothing to do with feature detection.

[-] DudeDudenson@lemmings.world 4 points 3 weeks ago

Aren't user agents just a plain text header? Couldn't a malicious agent just spoof a legitimate one?

[-] elrik@lemmy.world 7 points 3 weeks ago* (last edited 3 weeks ago)

That's correct, it is just plain text and it can easily be spoofed. You should never perform an auth check of any kind with the user agent.

In the above examples, it wouldn't really matter if someone spoofed the header as there generally isn't a benefit to the malicious agent.

Where some sites get into trouble though is if they have an implicit auth check using user agents. An example could be a paywalled recipe site. They want the recipe to be indexed by Google. If I spoof my user agent to be Googlebot, I'll get to view the recipe content they want indexed, bypassing the paywall.

But, an example of a more reasonable use for checking user agent strings for bots might be regional redirects. If a new user comes to my site, maybe I want to redirect to a localized version at a different URL based on their country. However, I probably don't want to do that if the agent is a bot, since the bot might be indexing a given URL from anywhere. If someone spoofed their user agent and they aren't redirected, no big deal.

[-] Xanthrax@lemmy.world 12 points 3 weeks ago* (last edited 3 weeks ago)

Web UI for touch screens is a lot different than keyboard and mouse. I still switch to desktop most of the time because the mobile site will lack critical info, though. They "have" to streamline the experience for mobile, but I hate it when they fully remove features.

[-] sacbuntchris@lemmy.world 10 points 3 weeks ago

Lazy web developers or clueless managers have entered the chat

[-] bleistift2@sopuli.xyz 1 points 2 weeks ago* (last edited 2 weeks ago)

I know Safari 15.3 doesn’t support feature Y, but I also know the current version does. Now I want to know if I can just use the feature or if I need to program around Safari 15.3. It would be nice to just look at the server logs from last month and see if someone still uses it.

[-] Tin 45 points 3 weeks ago

"yer a jedi, harry" - Gandalf

[-] WhiskyTangoFoxtrot@lemmy.world 4 points 3 weeks ago

Listen here, Gandalf, you fat oaf! I'm not a fucking Jedi!

[-] dan@upvote.au 44 points 3 weeks ago* (last edited 3 weeks ago)

User agents are essentially deprecated and are going to become less and less useful over time. The replacement is either client hints or feature detection, depending on what you're using it for.

[-] OpenStars@discuss.online 22 points 3 weeks ago

Is it... (scrolls wheel of browsers) Lynx?

[-] CanadaPlus@lemmy.sdf.org 13 points 3 weeks ago* (last edited 3 weeks ago)

I'm still amazed at how usable Lynx is, given the insane premise of the application.

[-] deltapi@lemmy.world 5 points 3 weeks ago

What's so insane about it? Web browsers are an evolution of the old gopher protocol. All this stuff has roots in text consoles.

[-] CanadaPlus@lemmy.sdf.org 3 points 3 weeks ago

The history makes plenty of sense, and explains why it's there in the fist place. The modern internet was not designed to use by console, though.

[-] simonced@lemmy.one 20 points 3 weeks ago

A URL is not an agent string, just saying.

[-] aaaaace 16 points 3 weeks ago

I want a WordPress plugin that refuses to load my site for anyyhing newer than Netscape 3 and pops up a modal "you need to upgrade your browser" pane.

[-] PrimeErective@startrek.website 15 points 3 weeks ago

A new browser touches the beacon

this post was submitted on 20 Sep 2024
445 points (100.0% liked)

Programmer Humor

19331 readers
1 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS