Skip to content

Commit

Permalink
update default device user-agent to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmood committed Aug 23, 2023
1 parent d2ad7cb commit 0af5471
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 26 deletions.
13 changes: 5 additions & 8 deletions lib/devices/generate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io/ioutil"
"net/http"
"path/filepath"
"strings"

"github.com/go-rod/rod/lib/utils"
Expand Down Expand Up @@ -55,10 +56,6 @@ func main() {
package devices
import (
"github.com/go-rod/rod/lib/devices"
)
var (
{{.code}}
)
Expand All @@ -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),
)
}

Expand Down Expand Up @@ -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
}

Expand Down
34 changes: 17 additions & 17 deletions lib/devices/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down

0 comments on commit 0af5471

Please sign in to comment.