Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nexcode opened this issue Jan 16, 2025 · 0 comments
Open

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

nexcode opened this issue Jan 16, 2025 · 0 comments
Labels
p2-bug Something isn't working

Comments

@nexcode
Copy link

nexcode commented Jan 16, 2025

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant