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

c.Page.PrintToPDF is stuck #151

Open
cbgz121 opened this issue Nov 13, 2024 · 2 comments
Open

c.Page.PrintToPDF is stuck #151

cbgz121 opened this issue Nov 13, 2024 · 2 comments

Comments

@cbgz121
Copy link

cbgz121 commented Nov 13, 2024

Hi, when i use this code, screenshot can work well but the pdf cannot. It is stuck this code: "pdfData, err := c.Page.PrintToPDF(ctx, pdfArgs)."

` screenshotName := "screenshot.jpg"
screenshotArgs := page.NewCaptureScreenshotArgs().
SetFormat("jpeg").
SetQuality(80)
screenshot, err := c.Page.CaptureScreenshot(ctx, screenshotArgs)
if err != nil {
return err
}
if err = ioutil.WriteFile(screenshotName, screenshot.Data, 0o644); err != nil {
return err
}

fmt.Printf("Saved screenshot: %s\n", screenshotName)

pdfName := "page.pdf"
f, err := os.Create(pdfName)
if err != nil {
	return err
}

pdfArgs := page.NewPrintToPDFArgs().
	SetTransferMode("ReturnAsStream") // Request stream.
pdfData, err := c.Page.PrintToPDF(ctx, pdfArgs)
if err != nil {
	return err
}`
@cbgz121 cbgz121 changed the title c.Target.CreateTarget returns incorrect targetid c.Page.PrintToPDF is stuck Nov 13, 2024
@mafredri
Copy link
Owner

Are you using the example as-is? https://github.com/mafredri/cdp/blob/e5a75ebc0b46b7dbf5553fc2ff6f2b11754d65ea/example_test.go

If yes, can you try to add logging and show the output? Example here:

newLogCodec := func(conn io.ReadWriter) rpcc.Codec {
return &LogCodec{conn: conn}
}
conn, err := rpcc.Dial("ws://"+TestSockSrv+"/example_logging", rpcc.WithCodec(newLogCodec))

And finally, what browser/version are you using?

@cbgz121
Copy link
Author

cbgz121 commented Nov 14, 2024

Are you using the example as-is? https://github.com/mafredri/cdp/blob/e5a75ebc0b46b7dbf5553fc2ff6f2b11754d65ea/example_test.go

If yes, can you try to add logging and show the output? Example here:

newLogCodec := func(conn io.ReadWriter) rpcc.Codec {
return &LogCodec{conn: conn}
}
conn, err := rpcc.Dial("ws://"+TestSockSrv+"/example_logging", rpcc.WithCodec(newLogCodec))

And finally, what browser/version are you using?

Yes, I am using that example, and I printed the log but it only returned this,

SEND: {"id":6,"method":"Page.printToPDF","params":{"transferMode":"ReturnAsStream"}}

it seems that the response was not received,

But when I manually navigate the browser to another address while the browser is stuck there, it prints out the error log.

RECV: {"method":"Page.frameStartedLoading","params":{"frameId":"5C7CCA45C475EE6A3946B82836BF66FC"}} RECV: {"method":"Page.frameNavigated","params":{"frame":{"id":"5C7CCA45C475EE6A3946B82836BF66FC","loaderId":"3B03AA43CF7D0BF506F8CE955E191711","url":"chrome://version/","domainAndRegistry":"","securityOrigin":"chrome://version","mimeType":"text/html","adFrameStatus":{"adFrameType":"none"},"secureContextType":"Secure","crossOriginIsolatedContextType":"NotIsolated","gatedAPIFeatures":[]},"type":"Navigation"}} RECV: {"method":"DOM.documentUpdated","params":{}} RECV: {"id":6,"error":{"code":-32000,"message":"Printing failed"}}

and i am using version 129.0.6667.0 of chromium

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

No branches or pull requests

2 participants