mssola / user_agent

This project has been moved, check the README.md file!

Home Page:https://github.com/mssola/useragent

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Electron Support

moonmeister opened this issue · comments

When Electron Apps(https://electron.atom.io/) are used it detects strangely. I'm on a mac and it's detecting electron apps as Safari, but then it's detecting the version of Safari not as the actual Safari version, nor the version of Electron, but the version of the app.

Franz detects as:

[2017/09/15 16:36:38 PDT] [DEBG] User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Franz/4.0.4 Chrome/52.0.2743.82 Electron/1.3.1 Safari/537.36
[2017/09/15 16:36:38 PDT] [DEBG] Detected Client: Safari 4.0.4

The Mattermost App Detects as:

[2017/09/15 16:37:16 PDT] [DEBG] User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Mattermost/3.7.1 Chrome/56.0.2924.87 Electron/1.6.11 Safari/537.36
[2017/09/15 16:37:16 PDT] [DEBG] Detected Client: Mattermost App - Safari 3.7.1

I'm not entirely sure how electron works but it seems like I should either be give Electron as the Browser and the Version of Electron in use, or if electron is simply using a Safari Window then the correct version of Safari (or the windows/linux browser counterpart).

Seems like the issue is here:

default:
	if sections[sectionIndex].name == "Chrome" {
		p.browser.Name = "Chrome"
	} else if sections[sectionIndex].name == "Chromium" {
		p.browser.Name = "Chromium"
	} else {
		p.browser.Name = "Safari"
	}

Seems like if it's a webkit engine and it can't detect any other browser it defaults to Safari. It seems like this detection should be a little more rigid if it can't detect any major/supported browser then it returns unknown or something like that instead of reporting incorrectly as Safari.

And Here's why we're randomly getting version 4.0.4:

if slen > 2 {
	sectionIndex := 2
	// The version after the engine comment is empty on e.g. Ubuntu
	// platforms so if this is the case, let's use the next in line.
	if sections[2].version == "" && slen > 3 {
		sectionIndex = 3
	}
	p.browser.Version = sections[sectionIndex].version

Seems arbitrary to pull the 2nd or 3rd number as the version.

I don't mean to bash what you've done here. Reading ua strings is hard for person let alone a computer. I'm just trying to understand.