Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After setting the default system device, the viewport display height and width are reversed. #998

Closed
twolao opened this issue Jan 3, 2024 · 2 comments
Labels
question Questions related to rod

Comments

@twolao
Copy link

twolao commented Jan 3, 2024

Rod Version: v0.114.5

The code to demonstrate your question

  1. Clone Rod to your local and cd to the repository:

    git clone https://github.com/go-rod/rod
    cd rod
  2. Use your code to replace the content of function TestRod in file rod_test.go.

  3. Test your code with: go test -run TestRod, make sure it fails as expected.

  4. 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

2

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?

@twolao twolao added the question Questions related to rod label Jan 3, 2024
Copy link

github-actions bot commented Jan 3, 2024

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

@ysmood
Copy link
Member

ysmood commented Jan 3, 2024

Change your code from:

browser := rod.New().ControlURL(url).DefaultDevice(devices.LaptopWithHiDPIScreen)

To:

browser := rod.New().ControlURL(url).DefaultDevice(devices.LaptopWithHiDPIScreen.Landscape())

@ysmood ysmood closed this as completed Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Questions related to rod
Projects
None yet
Development

No branches or pull requests

2 participants