After setting the default system device, the viewport display height and width are reversed.
twolao opened this issue · comments
Rod Version: v0.114.5
The code to demonstrate your question
-
Clone Rod to your local and cd to the repository:
git clone https://github.com/go-rod/rod cd rod
-
Use your code to replace the content of function
TestRod
in filerod_test.go
. -
Test your code with:
go test -run TestRod
, make sure it fails as expected. -
Replace ALL THE CONTENT under "The code to demonstrate your question" with your
TestRod
function, like below:
package main
import (
"github.com/go-rod/rod"
"github.com/go-rod/rod/lib/launcher"
"github.com/go-rod/rod/lib/devices"
"os"
"log"
"fmt"
"time"
"os/signal"
"syscall"
)
var err error
func main() {
l := launcher.New().
Headless(false).
Devtools(false).
Env(append(os.Environ(), "TZ=Asia/Tokyo")...).
Leakless(true)
url, err := l.Launch()
if err != nil {
fmt.Println("Error launching browser:", err)
return
}
defer l.Cleanup()
browser := rod.New().ControlURL(url).DefaultDevice(devices.LaptopWithHiDPIScreen)
if err = browser.Connect(); err != nil {
fmt.Println("Error connecting to browser:", err)
return
}
defer browser.MustClose()
page := browser.MustPage()
page.Navigate("https://browserleaks.com/javascript")
ticker := time.NewTicker(30 * time.Second)
quit := make(chan struct{})
go func() {
for {
select {
case <-ticker.C:
log.Println("some code")
case <-quit:
ticker.Stop()
return
}
}
}()
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
<-sigs
close(quit)
fmt.Println("browser closed")
}
What you got
What you expect to see
window.innerWidth 1440
window.innerHeight 900
What have you tried to solve the question
Original device definition:
LaptopWithHiDPIScreen = Device{
Title: "Laptop with HiDPI screen",
Capabilities: []string{},
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,
Horizontal: ScreenSize{
Width: 1440,
Height: 900,
},
Vertical: ScreenSize{
Width: 900,
Height: 1440,
},
},
}
Delete the Vertical part of the definition and it will display normally. The default display is to select Horizontal or vertical. Where to control it?
Please fix the format of your markdown:
90 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## What have you tried to solve the question"]
generated by check-issue
Change your code from:
browser := rod.New().ControlURL(url).DefaultDevice(devices.LaptopWithHiDPIScreen)
To:
browser := rod.New().ControlURL(url).DefaultDevice(devices.LaptopWithHiDPIScreen.Landscape())