Skip to content

fix(cdp): handle missing timing fields in the response from CDP#581

Open
zikani03 wants to merge 1 commit intoplaywright-community:mainfrom
zikani03:fix/handle-parsing-float
Open

fix(cdp): handle missing timing fields in the response from CDP#581
zikani03 wants to merge 1 commit intoplaywright-community:mainfrom
zikani03:fix/handle-parsing-float

Conversation

@zikani03
Copy link

Fixed handling of float values from the CDP timing response. To handle situation where an implementation of the CDP doesn't return appropriate timings or is missing some fields.

Go: 1.25
Playwright-go: v0.5200.1
Browser: Chromium-ish -> LightPanda via CDP

Reproduce

I was trying to use LightPanda's Browser which has support for CDP to use as an alternative to Chromium.

Follow the steps in order to reproduce.

  1. Download LightPanda Browser
  2. Run LightPanda Browser's CDP server
$ lightpanda-x86_64-linux serve --port 9226 --log_level debug
  1. Create the following Go program
package main

import (
	"fmt"
	"log"

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

func main() {
	err := run()
	if err != nil {
		log.Fatal(err)
	}
}
func run() error {

	err := playwrightgo.Install(&playwrightgo.RunOptions{
		Browsers: []string{"chromium"},
		DryRun:   true,
	})
	if err != nil {
		return fmt.Errorf("could not launch playwright: %w", err)
	}

	pw, err := playwrightgo.Run()
	if err != nil {
		return fmt.Errorf("could not launch playwright: %w", err)
	}

	browser, err := pw.Chromium.ConnectOverCDP("ws://localhost:9226")
	if err != nil {
		return fmt.Errorf("could not launch LightPanda via CDP: %w", err)
	}
	context, err := browser.NewContext()
	if err != nil {
		return fmt.Errorf("could not create context: %w", err)
	}
	page, err := context.NewPage()
	if err != nil {
		return fmt.Errorf("could not create page: %w", err)
	}

	_, err = page.Goto("https://playwright.dev/")
	if err != nil {
		return fmt.Errorf("could not goto: %w", err)
	}

	loc := page.Locator(`a[href="/community/welcome"]`)
	assertions := playwrightgo.NewPlaywrightAssertions()
	assert := assertions.Locator(loc)

	err = assert.ToHaveText("Community")
	if err != nil {
		return fmt.Errorf("could assert community link: %w", err)
	}

	err = browser.Close()
	if err != nil {
		return fmt.Errorf("could not close browser: %w", err)
	}
	err = pw.Stop()
	if err != nil {
		return fmt.Errorf("could not stop Playwright: %w", err)
	}

	return nil

}
  1. Run the program go run main.go

  2. Observe that there's a panic with the following in the error trace:

panic: interface conversion: interface {} is nil, not float64

goroutine 50 [running]:
github.com/playwright-community/playwright-go.newResponse(0xc0001b4000, {0xc000114cf0, 0x8}, {0xc00014aff0, 0x29}, 0xc0001a2db0)

Signed-off-by: Zikani Nyirenda Mwase <zikani.nmwase@ymail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant