From 0af5471d5b16a38276cdc6a81c2efc39658f8dbe Mon Sep 17 00:00:00 2001 From: Yad Smood Date: Wed, 23 Aug 2023 11:18:59 +0800 Subject: [PATCH] update default device user-agent to latest --- lib/devices/generate/main.go | 13 +++++-------- lib/devices/list.go | 34 +++++++++++++++++----------------- page_test.go | 2 +- 3 files changed, 23 insertions(+), 26 deletions(-) diff --git a/lib/devices/generate/main.go b/lib/devices/generate/main.go index a2adacce..d2380fe9 100644 --- a/lib/devices/generate/main.go +++ b/lib/devices/generate/main.go @@ -5,6 +5,7 @@ import ( "fmt" "io/ioutil" "net/http" + "path/filepath" "strings" "github.com/go-rod/rod/lib/utils" @@ -55,10 +56,6 @@ func main() { package devices - import ( - "github.com/go-rod/rod/lib/devices" - ) - var ( {{.code}} ) @@ -70,8 +67,8 @@ func main() { utils.Exec("gofumpt -w", path) utils.Exec( "go run github.com/ysmood/golangci-lint@latest -- "+ - "run --no-config --fix", - path, + "run --fix", + filepath.Dir(path), ) } @@ -108,9 +105,9 @@ func normalizeName(name string) string { func getUserAgent(val gson.JSON) string { ua := val.Get("user-agent").String() if ua == "" { - return "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" + return "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36" } - ua = strings.ReplaceAll(ua, "%s", "87.0.4280.88") + ua = strings.ReplaceAll(ua, "%s", "114.0.0.0") return ua } diff --git a/lib/devices/list.go b/lib/devices/list.go index 07603ed8..c747869e 100644 --- a/lib/devices/list.go +++ b/lib/devices/list.go @@ -122,7 +122,7 @@ var ( Nexus4 = Device{ Title: "Nexus 4", Capabilities: []string{"touch", "mobile"}, - UserAgent: "Mozilla/5.0 (Linux; Android 4.4.2; Nexus 4 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Mobile Safari/537.36", + UserAgent: "Mozilla/5.0 (Linux; Android 4.4.2; Nexus 4 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Mobile Safari/537.36", AcceptLanguage: "en", Screen: Screen{ DevicePixelRatio: 2, @@ -141,7 +141,7 @@ var ( Nexus5 = Device{ Title: "Nexus 5", Capabilities: []string{"touch", "mobile"}, - UserAgent: "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Mobile Safari/537.36", + UserAgent: "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Mobile Safari/537.36", AcceptLanguage: "en", Screen: Screen{ DevicePixelRatio: 3, @@ -160,7 +160,7 @@ var ( Nexus5X = Device{ Title: "Nexus 5X", Capabilities: []string{"touch", "mobile"}, - UserAgent: "Mozilla/5.0 (Linux; Android 8.0.0; Nexus 5X Build/OPR4.170623.006) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Mobile Safari/537.36", + UserAgent: "Mozilla/5.0 (Linux; Android 8.0.0; Nexus 5X Build/OPR4.170623.006) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Mobile Safari/537.36", AcceptLanguage: "en", Screen: Screen{ DevicePixelRatio: 2, @@ -179,7 +179,7 @@ var ( Nexus6 = Device{ Title: "Nexus 6", Capabilities: []string{"touch", "mobile"}, - UserAgent: "Mozilla/5.0 (Linux; Android 7.1.1; Nexus 6 Build/N6F26U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Mobile Safari/537.36", + UserAgent: "Mozilla/5.0 (Linux; Android 7.1.1; Nexus 6 Build/N6F26U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Mobile Safari/537.36", AcceptLanguage: "en", Screen: Screen{ DevicePixelRatio: 3, @@ -198,7 +198,7 @@ var ( Nexus6P = Device{ Title: "Nexus 6P", Capabilities: []string{"touch", "mobile"}, - UserAgent: "Mozilla/5.0 (Linux; Android 8.0.0; Nexus 6P Build/OPP3.170518.006) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Mobile Safari/537.36", + UserAgent: "Mozilla/5.0 (Linux; Android 8.0.0; Nexus 6P Build/OPP3.170518.006) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Mobile Safari/537.36", AcceptLanguage: "en", Screen: Screen{ DevicePixelRatio: 3, @@ -217,7 +217,7 @@ var ( Pixel2 = Device{ Title: "Pixel 2", Capabilities: []string{"touch", "mobile"}, - UserAgent: "Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Mobile Safari/537.36", + UserAgent: "Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Mobile Safari/537.36", AcceptLanguage: "en", Screen: Screen{ DevicePixelRatio: 2, @@ -236,7 +236,7 @@ var ( Pixel2XL = Device{ Title: "Pixel 2 XL", Capabilities: []string{"touch", "mobile"}, - UserAgent: "Mozilla/5.0 (Linux; Android 8.0.0; Pixel 2 XL Build/OPD1.170816.004) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Mobile Safari/537.36", + UserAgent: "Mozilla/5.0 (Linux; Android 8.0.0; Pixel 2 XL Build/OPD1.170816.004) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Mobile Safari/537.36", AcceptLanguage: "en", Screen: Screen{ DevicePixelRatio: 3, @@ -255,7 +255,7 @@ var ( LGOptimusL70 = Device{ Title: "LG Optimus L70", Capabilities: []string{"touch", "mobile"}, - UserAgent: "Mozilla/5.0 (Linux; U; Android 4.4.2; en-us; LGMS323 Build/KOT49I.MS32310c) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/87.0.4280.88 Mobile Safari/537.36", + UserAgent: "Mozilla/5.0 (Linux; U; Android 4.4.2; en-us; LGMS323 Build/KOT49I.MS32310c) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/114.0.0.0 Mobile Safari/537.36", AcceptLanguage: "en", Screen: Screen{ DevicePixelRatio: 1, @@ -369,7 +369,7 @@ var ( GalaxyS5 = Device{ Title: "Galaxy S5", Capabilities: []string{"touch", "mobile"}, - UserAgent: "Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Mobile Safari/537.36", + UserAgent: "Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Mobile Safari/537.36", AcceptLanguage: "en", Screen: Screen{ DevicePixelRatio: 3, @@ -502,7 +502,7 @@ var ( Nexus10 = Device{ Title: "Nexus 10", Capabilities: []string{"touch", "mobile"}, - UserAgent: "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 10 Build/MOB31T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36", + UserAgent: "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 10 Build/MOB31T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36", AcceptLanguage: "en", Screen: Screen{ DevicePixelRatio: 2, @@ -521,7 +521,7 @@ var ( Nexus7 = Device{ Title: "Nexus 7", Capabilities: []string{"touch", "mobile"}, - UserAgent: "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 7 Build/MOB30X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36", + UserAgent: "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 7 Build/MOB30X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36", AcceptLanguage: "en", Screen: Screen{ DevicePixelRatio: 2, @@ -578,7 +578,7 @@ var ( LaptopWithTouch = Device{ Title: "Laptop with touch", Capabilities: []string{"touch"}, - UserAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36", + UserAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36", AcceptLanguage: "en", Screen: Screen{ DevicePixelRatio: 1, @@ -597,7 +597,7 @@ var ( LaptopWithHiDPIScreen = Device{ Title: "Laptop with HiDPI screen", Capabilities: []string{}, - UserAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36", + UserAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36", AcceptLanguage: "en", Screen: Screen{ DevicePixelRatio: 2, @@ -616,7 +616,7 @@ var ( LaptopWithMDPIScreen = Device{ Title: "Laptop with MDPI screen", Capabilities: []string{}, - UserAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36", + UserAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36", AcceptLanguage: "en", Screen: Screen{ DevicePixelRatio: 1, @@ -635,7 +635,7 @@ var ( MotoG4 = Device{ Title: "Moto G4", Capabilities: []string{"touch", "mobile"}, - UserAgent: "Mozilla/5.0 (Linux; Android 6.0.1; Moto G (4)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Mobile Safari/537.36", + UserAgent: "Mozilla/5.0 (Linux; Android 6.0.1; Moto G (4)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Mobile Safari/537.36", AcceptLanguage: "en", Screen: Screen{ DevicePixelRatio: 3, @@ -654,7 +654,7 @@ var ( SurfaceDuo = Device{ Title: "Surface Duo", Capabilities: []string{"touch", "mobile"}, - UserAgent: "Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Mobile Safari/537.36", + UserAgent: "Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Mobile Safari/537.36", AcceptLanguage: "en", Screen: Screen{ DevicePixelRatio: 2, @@ -673,7 +673,7 @@ var ( GalaxyFold = Device{ Title: "Galaxy Fold", Capabilities: []string{"touch", "mobile"}, - UserAgent: "Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Mobile Safari/537.36", + UserAgent: "Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Mobile Safari/537.36", AcceptLanguage: "en", Screen: Screen{ DevicePixelRatio: 3, diff --git a/page_test.go b/page_test.go index f379ca6a..53844211 100644 --- a/page_test.go +++ b/page_test.go @@ -147,7 +147,7 @@ func TestSetUserAgent(t *testing.T) { g.newPage().MustSetUserAgent(nil).MustNavigate(s.URL()) wg.Wait() - g.Eq(ua, "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36") + g.Eq(ua, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36") g.Eq(lang, "en") }