Skip to content

[Bug]: Router breaks if call HeadersArray() #519

Open
@nexcode

Description

@nexcode

Environments

Bug description
Router breaks down if you call route.Request().HeadersArray()

To Reproduce

package main

import (
	"fmt"
	"log"
	"time"

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

func main() {
	runOptions := &playwright.RunOptions{
		SkipInstallBrowsers: true,
	}

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

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

	browser, err := pw.Chromium.Connect("ws://127.0.0.1:3000/playwright/chromium")
	if err != nil {
		log.Fatalf("could not connect to browser: %v", err)
	}

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

	err = browserContext.Route("**/*", func(route playwright.Route) {
		_, err := route.Request().HeadersArray()
		if err != nil {
			log.Fatalf("HeadersArray call error: %v", err)
		}

		fmt.Println("router callback")
		route.Continue()
	})
	if err != nil {
		log.Fatalf("could not create route: %v", err)
	}

	page, err := browserContext.NewPage()
	if err != nil {
		log.Fatalf("could not create page: %v", err)
	}

	fmt.Println("preGoto")
	_, err = page.Goto("https://news.ycombinator.com")
	fmt.Println("postGoto")

	if err != nil {
		log.Fatalf("could not goto: %v", err)
	}

	time.Sleep(time.Minute)
}

If you delete this call from router:

_, err := route.Request().HeadersArray()

Then everything will work, otherwise it freezes without additional errors

Additional context

Normal console output / without route.Request().HeadersArray():

preGoto
router callback
router callback
router callback
router callback
router callback
router callback
postGoto

Broken output / with route.Request().HeadersArray():

preGoto
2025/01/16 20:11:53 could not goto: Frame.Goto https://news.ycombinator.com: playwright: timeout: Timeout 30000ms exceeded.
postGoto

Metadata

Metadata

Assignees

No one assigned

    Labels

    p2-bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions