-
-
Notifications
You must be signed in to change notification settings - Fork 201
Description
Environments
- playwright-go Version: 0.4901.0
- Browser: Chromium
- OS and version: Windows 11 / Ubuntu 24.04
Bug description
When running my program that uses playwright-go for an extended period, the node process starts consuming more and more RAM.
An hour after launching my program, the node process consumes the following amount of memory:
After 4 days of continuous operation, the memory consumption increases:
Based on the RSS field, after one hour of running the program, the node process was consuming approximately 73 MB of memory (RSS: 75,244 KB). After 4 days of operation, it increased to approximately 296 MB (RSS: 302,844 KB).
This indicates a steady increase in memory usage by the node process, which may suggest a memory leak.
To Reproduce
Please consider the minimal code example that demonstrates the issue:
package main
import (
"fmt"
"log"
"time"
"github.com/playwright-community/playwright-go"
)
type PlaywrightService struct {
PlaywrightInstance *playwright.Playwright
BrowserInstance playwright.Browser
}
func main() {
playwrightService := &PlaywrightService{}
playwrightInstance, err := playwright.Run()
if err != nil {
log.Fatalf("Failed to start Playwright: %v", err)
} else {
playwrightService.PlaywrightInstance = playwrightInstance
}
defer playwrightService.PlaywrightInstance.Stop()
browserInstance, err := playwrightInstance.Chromium.Launch(playwright.BrowserTypeLaunchOptions{
Headless: playwright.Bool(true),
})
if err != nil {
log.Fatalf("Failed to launch Chromium: %v", err)
} else {
playwrightService.BrowserInstance = browserInstance
}
defer playwrightService.BrowserInstance.Close()
for {
if err := playwrightService.OpenURL("http://www.msftconnecttest.com/connecttest.txt"); err != nil {
log.Printf("Failed to open URL: %v", err)
}
time.Sleep(10 * time.Second)
}
}
func (ps *PlaywrightService) OpenURL(url string) error {
context, err := ps.BrowserInstance.NewContext()
if err != nil {
return fmt.Errorf("creating browser context: %v", err)
}
defer context.Close()
page, err := context.NewPage()
if err != nil {
return fmt.Errorf("creating new page: %v", err)
}
defer page.Close()
if _, err := page.Goto(url, playwright.PageGotoOptions{
Timeout: playwright.Float(5000),
}); err != nil {
return fmt.Errorf("navigating to %s: %v", url, err)
}
return nil
}
Additional context
In this code, the program continuously opens the specified URL in an infinite loop with a 10-second interval. Each cycle creates a new browser context and a new page, which are then closed using defer. Despite this, there is a constant increase in memory consumption by the node process. This may indicate a possible memory leak in playwright-go or an issue in the interaction with Node.js.
I would appreciate any help in resolving this problem.