Skip to content

Viewport definition issue #403

Description

@drbornot

I'm facing an issue when extending my browser-based desktop tests to mobile devices. If I set the device Viewport, it fails:
1- when chromium, tests always fail and running in browser mode I see the page start moving when the click action is executed
2- when webkit, tests pass only if browser mode (headless true)...otherwise they fail

If I don't set Viewport then tests pass

Below is my code, if I disable the Viewport setting then it is a success:

        runOption := &playwright.RunOptions{
		Browsers: []string{"chromium", "webkit"},
	}

	err = playwright.Install(runOption)
	if err != nil {
		log.Fatalf("could not install playwright dependencies: %v", err)
	}

	pw, err = playwright.Run()
	if err != nil {
		log.Fatalf("could not start Playwright: %v", err)
	}

        pwDevice = pw.Devices["Pixel 7"]

	switch pwDevice.DefaultBrowserType {
	case "chromium":
		testBrowser, err = pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{
			Channel:  playwright.String("chromium"),
			Headless: playwright.Bool(Headless),
			Args: []string{
				"--disable-features=IsolateOrigins,site-per-process",
				"--disable-setuid-sandbox",
				"--disable-web-security",
				"--disable-blink-features",
				"--disable-blink-features=AutomationControlled",
				"--incognito",
				"--disable-application-cache",
				"--no-sandbox",
				"--disable-dev-shm-usage",
				"--enable-automation",
				"--remote-allow-origins=*",
			},
		})
		if err != nil {
			log.Fatalf("could not launch: %v", err)
		}
	case "webkit":
		testBrowser, err = pw.WebKit.Launch(playwright.BrowserTypeLaunchOptions{
			Channel:  playwright.String("webkit"),
			Headless: playwright.Bool(Headless),
		})
		if err != nil {
			log.Fatalf("could not launch: %v", err)
		}
	}

        ctx, err = testBrowser.NewContext(playwright.BrowserNewContextOptions{
	        Viewport:          pwDevice.Viewport,
	        UserAgent:         playwright.String(pwDevice.UserAgent),
	        DeviceScaleFactor: playwright.Float(pwDevice.DeviceScaleFactor),
	        IsMobile:          playwright.Bool(pwDevice.IsMobile),
	        HasTouch:          playwright.Bool(pwDevice.HasTouch),
        })
        require.NoError(t, err)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions