Giter Site home page Giter Site logo

unexpected panic about chromedp HOT 10 CLOSED

chromedp avatar chromedp commented on May 15, 2024
unexpected panic

from chromedp.

Comments (10)

kenshaw avatar kenshaw commented on May 15, 2024 2

I just pushed a simple fix around that so that it won't panic. Yes, the entire project is severely lacking in documentation at the moment. I just haven't had time to really do the write ups necessary. However, I do believe we've done a fairly good job at documenting the actual package code, and GoDoc would be your friend here.

Some brief explanations:

  • runner is just a simple package to help with launching Chrome instances (ie, processes).
  • client is a simple package to deal with the low-level, "wire" parts of Chrome Debugging Protocol (ie, the HTTP / WebSocket stuff).
  • chromedp is the high level "target manager" code that manages an actual Chrome process via the Chrome Debugging Protocol.
  • cdp contains the generated code for the actual Chrome Debugging Protocol domains. Originally, this was called domains but I felt that domains was too generic of a name, and cdpdomains was too long. This package is generated entirely by the cmd/chromedp-gen tool, and is fairly well documented on its own.
  • kb contains mostly generated code for all of the Virtual Keys to use with input actions. This was made into a separate package, so that the chromed.* namespace wasn't polluted with the approximate 200+ key definitions.

from chromedp.

kenshaw avatar kenshaw commented on May 15, 2024

Could you provide the actual panic?And information on the environment you're using?

from chromedp.

kenshaw avatar kenshaw commented on May 15, 2024

You're ignoring the error returned from cdp.New. If you actually check, c returned from cdp.New is nil.

from chromedp.

kenshaw avatar kenshaw commented on May 15, 2024

The problem here is that you are using the headless example. This example assumes you already have a Chrome Debugging Protocol client running on port 9222. You can use chromedp/runner or some other way to launch a Chrome process. Also, please checkout the way the chromedp package is unit tested. There are fully automated headless examples there using the Pool type.

from chromedp.

rikonor avatar rikonor commented on May 15, 2024

Thank you, I will check the unit tests.

Ignoring the error from cdp.New was intentional and only after verifying no error was returned.

I was indeed trying to run it using a headless Chrome instance, using your public docker image:

➜  ~ docker run -it -p 9222:9222 --rm --name chrome-headless knqz/chrome-headless
[0313/011426.476607:WARNING:resource_bundle.cc(338)] locale_file_path.empty() for locale
[0313/011426.519486:WARNING:resource_bundle.cc(338)] locale_file_path.empty() for locale
[0313/011426.599263:WARNING:resource_bundle.cc(338)] locale_file_path.empty() for locale

Then trying to run the following:

package main

import (
	"context"
	"fmt"
	"log"

	cdp "github.com/knq/chromedp"
	"github.com/knq/chromedp/client"
)

func main() {
	ctx := context.Background()

	// create chrome instance
	cl := client.New()
	fmt.Println("cl", cl)

	tgts := cl.WatchPageTargets(ctx)
	fmt.Println("tgts", tgts)

	c, err := cdp.New(ctx, cdp.WithTargets(tgts))
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("c", c)

	// shutdown chrome
	fmt.Println("Attempting to shutdown..")
	c.Shutdown(ctx)
}

Causes the following panic:

➜  regular go run main.go
cl &{http://localhost:9222/json 100000000 5000000000   {{0 0} 0 0 0 0}}
tgts 0xc4200f58c0
c &{<nil> [] 0xc4200f58c0 0xc4200ba210 [0xc4200ba210] map[bb3bc025-e4ea-429e-a57f-25e7505e240b:0] 0x6a000 0x70de0 0x70df0 {{0 0} 0 0 0 0}}
Attempting to shutdown..

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xcc535]

goroutine 1 [running]:
panic(0x3d4dc0, 0xc42000c0c0)
        /usr/local/go/src/runtime/panic.go:500 +0x1a1
github.com/knq/chromedp/runner.(*Runner).Port(0x0, 0x0)
        /Users/orrikon/workspace/go/src/github.com/knq/chromedp/runner/runner.go:261 +0xb5
github.com/knq/chromedp/runner.(*Runner).Client(0x0, 0x0, 0x0, 0x0, 0x19)
        /Users/orrikon/workspace/go/src/github.com/knq/chromedp/runner/runner.go:281 +0x35
github.com/knq/chromedp/runner.(*Runner).Shutdown(0x0, 0x6301c0, 0xc42007a188, 0x0, 0x0, 0x0, 0x19, 0x0)
        /Users/orrikon/workspace/go/src/github.com/knq/chromedp/runner/runner.go:196 +0x67
github.com/knq/chromedp.(*CDP).Shutdown(0xc4200a6240, 0x6301c0, 0xc42007a188, 0x0, 0x0, 0x0, 0x0, 0x0)
        /Users/orrikon/workspace/go/src/github.com/knq/chromedp/chromedp.go:156 +0xbe
main.main()
        /Users/orrikon/workspace/go/src/github.com/rikonor/tests/chromedp/regular/main.go:30 +0x438
exit status 2

from chromedp.

kenshaw avatar kenshaw commented on May 15, 2024

This is a gotcha on the way that Go deals with types. You need to check the error returned by chromedp.New(). It is most likely the timeout waiting for initial target. This generally means that the remote client cannot be connected to.

from chromedp.

rikonor avatar rikonor commented on May 15, 2024

I'm not sure that would help in this case given that from the log I pasted it looks like the error returned from cdp.New is nil.

from chromedp.

kenshaw avatar kenshaw commented on May 15, 2024

Shutdown should not be called when you are using chromedp.New with WatchTargets. Shutdown is just a shorthand to call the process runner's Shutdown.

You will note in the headless example that there is no call to Shutdown. I'll add a check, however, so that if CDP.Shutdown is called, it won't panic.

from chromedp.

rikonor avatar rikonor commented on May 15, 2024

Ah I see. Thanks for the explanation.

Might be a good idea to elaborate a bit on the role of Runner, Client, etc in the readme. I may have missed any explanation if they already exist, but if not it would be really helpful!

Thanks again,
Or

from chromedp.

rikonor avatar rikonor commented on May 15, 2024

Neat. Thanks for the explanation!

from chromedp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.