playwright-community / playwright-go

Playwright for Go a browser automation library to control Chromium, Firefox and WebKit with a single API.
https://playwright-community.github.io/playwright-go/
MIT License
1.94k stars 144 forks source link

[Bug]: access multiple websites. Firefox browser opens multiple windows #450

Closed twolao closed 2 months ago

twolao commented 2 months ago

Environments

Bug description

To Reproduce Please provide a mini reproduction rather than just a description. For example:

package main

import (
    "log"
    "time"

    "github.com/playwright-community/playwright-go"
)

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

    option := playwright.BrowserTypeLaunchOptions{
        Headless: playwright.Bool(false),
    }
    browser, err := pw.Firefox.Launch(option)
    if err != nil {
        log.Fatalf("could not launch browser: %v", err)
    }
    defer browser.Close()

    context, err := browser.NewContext()
    if err != nil {
        log.Fatalf("could not create context: %v", err)
    }
    defer context.Close()

    sites := []string{
        "https://weibo.com",
        "https://google.com",
        "https://wikipedia.org",
    }

    for _, site := range sites {
        page, err := context.NewPage()
        if err != nil {
            log.Fatalf("could not create page: %v", err)
        }

        if _, err := page.Goto(site); err != nil {
            log.Fatalf("could not goto: %v", err)
        }
        log.Printf("Visiting: %s", site)
    }
    time.Sleep(1 * time.Minute)
}

Additional context Add any other context about the problem here.

The program starts to access multiple websites. The Firefox browser opens multiple windows, while using Chromium opens multiple tab pages. How to set up Firefox to open multiple tab pages instead of multiple windows?

canstand commented 2 months ago

https://github.com/microsoft/playwright/issues/3696