Comments (10)
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 calleddomains
but I felt thatdomains
was too generic of a name, andcdpdomains
was too long. This package is generated entirely by thecmd/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 thechromed.*
namespace wasn't polluted with the approximate 200+ key definitions.
from chromedp.
Could you provide the actual panic?And information on the environment you're using?
from chromedp.
You're ignoring the error returned from cdp.New
. If you actually check, c
returned from cdp.New
is nil.
from chromedp.
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.
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.
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.
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.
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.
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.
Neat. Thanks for the explanation!
from chromedp.
Related Issues (20)
- Navigate Hangup with custom url scheme HOT 1
- page.StopLoading() cannot stop navigate
- chrome failed to start with no detail error
- Screenshot from remote browser
- context canceled even with new context HOT 1
- Download events being omitted on the page level but chromedp listens for it on the Browser level HOT 1
- Image not showing up in header
- Can't use proxy and open multiple tabs ?
- Target.targetCrashed > errorCode 11 with chromedp.Navigate() in Docker container environnement HOT 7
- Is it possible to use the net/http client in chromedp ? HOT 1
- GetOuterHTML().WithPierce(true) not returning <iframe> contents
- How to execute JavaScript in a specified context? HOT 1
- How to set the state of ShadowDOM from closed to open?
- Question: condition for set FooterTemplate
- Is it possible to capture error messages related to CORS, CSP violations, mixed-content violations, etc.?
- Can I Capture Raw HTTP Data?
- How to start chrome in arm environment?Are there any other plans?
- Why can't I listen to my iframe's network requests
- How i get dpi of chrome
- Import cookie using json
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chromedp.