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
2.25k stars 163 forks source link

[Bug]: The recorded video has no sound #499

Closed kingparks closed 1 month ago

kingparks commented 1 month ago

Environments

Bug description

To Reproduce

package main

import (
    "fmt"
    "github.com/playwright-community/playwright-go"
    "log"
)

func main() {
    err := playwright.Install(&playwright.RunOptions{
        SkipInstallBrowsers: true,
    })
    if err != nil {
        log.Fatalf("could not install playwright: %v", err)
    }
    pw, err := playwright.Run()
    if err != nil {
        log.Fatalf("could not launch playwright: %v", err)
    }
    browser, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{
        Channel:  playwright.String("chrome"),
        Headless: playwright.Bool(false),
    })
    if err != nil {
        log.Fatalf("could not launch Chromium: %v", err)
    }
    page, err := browser.NewPage(playwright.BrowserNewPageOptions{
        Screen: &playwright.Size{
            Width:  1920,
            Height: 1080,
        },
        RecordVideo: &playwright.RecordVideo{
            Dir: "videos/",
            Size: &playwright.Size{
                Width:  1920,
                Height: 1080,
            },
        },
    })
    if err != nil {
        log.Fatalf("could not create page: %v", err)
    }
    if _, err = page.Goto("https://xxx.video"); err != nil {
        log.Fatalf("could not goto: %v", err)
    }
    err = page.Locator("#PlayButtonBig").Click()
    if err != nil {
        log.Fatalf("could not click entries: %v", err)
    }
    page.WaitForTimeout(10000)
    if err := page.Close(); err != nil {
        log.Fatalf("failed to close page: %v", err)
    }
    path, err := page.Video().Path()
    if err != nil {
        log.Fatalf("failed to get video path: %v", err)
    }
    fmt.Printf("Saved to %s\n", path)
    if err = browser.Close(); err != nil {
        log.Fatalf("could not close browser: %v", err)
    }
    if err = pw.Stop(); err != nil {
        log.Fatalf("could not stop Playwright: %v", err)
    }
}

There is no sound when playing the output file xxx.webm. Hope there is sound.

kingparks commented 1 month ago

no voice, no audio

canstand commented 1 month ago

You can use BrowserTypeLaunchOptions{ ignoreDefaultArgs: } to filter out --mute-audio from default arguments (for chromium).

kingparks commented 1 month ago

You can use BrowserTypeLaunchOptions{ ignoreDefaultArgs: } to filter out --mute-audio from default arguments (for chromium).

    browser, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{
        IgnoreDefaultArgs: []string{"--mute-audio"},
        Channel:           playwright.String("chrome"),
        Headless:          playwright.Bool(false),
    })

thx, but not working. During the recording process, sound can be heard, but there is no sound when playing the output file

canstand commented 1 month ago

According to upstream https://github.com/microsoft/playwright/issues/4870, recording audio is not supported.