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

Warning when running page.setDocumentContent #12

Closed
lehnenb opened this issue Sep 22, 2020 · 1 comment
Closed

Warning when running page.setDocumentContent #12

lehnenb opened this issue Sep 22, 2020 · 1 comment

Comments

@lehnenb
Copy link

lehnenb commented Sep 22, 2020

github.com/chromedp/chromedp v0.5.3
github.com/chromedp/cdproto v0.0.0-20200709115526-d1f6fc58448b
Google Chrome 85.0.4183.102
go version go1.14.4 darwin/amd64
MacOs Catalina version 10.15.4 

I've been implementing a simple HTML to PDF service.
Everything works perfectly and the program delivers the right output.
However, I noticed that every time I call the page.setDocumentContent I get the following warning:

ERROR: received DOM.documentUpdated when there's no top-level frame

Following is an example of how to trigger the error:

package main

import (
	"context"

	"github.com/chromedp/cdproto/cdp"
	"github.com/chromedp/cdproto/page"
	"github.com/chromedp/chromedp"
)

type pageHandler func(ctx context.Context, frameID cdp.FrameID) error

func main() {
	exCtx, cancel := newExecContext()
	defer cancel()

	newPageExec(exCtx, func(tabCtx context.Context, frameID cdp.FrameID) error {
		page.
			SetDocumentContent(frameID, `
				<html>
					<head></head>
					<body>
						<h1>Test</h1>
					</body>
				</html>
			`).
			Do(tabCtx)

		return nil
	})
}

func newExecContext() (context.Context, context.CancelFunc) {
	allocatorOptions := append(
		chromedp.DefaultExecAllocatorOptions[:],
		chromedp.Flag("headless", true),
		chromedp.Flag("disable-gpu", true),
	)

	ctx, cancel := chromedp.NewExecAllocator(
		context.Background(),
		allocatorOptions...,
	)

	return ctx, cancel
}

func newPageExec(execCtx context.Context, handler pageHandler) {
	newTabCtx, cancel := chromedp.NewContext(execCtx)
	chromedp.Run(newTabCtx, taskHandler(handler))
	cancel()
}

func taskHandler(handler pageHandler) chromedp.Tasks {
	return chromedp.Tasks{
		chromedp.ActionFunc(func(ctx context.Context) error {
			frameTree, err := page.GetFrameTree().Do(ctx)

			if err != nil {
				return err
			}

			err = handler(ctx, frameTree.Frame.ID)

			if err != nil {
				return err
			}

			return nil
		}),
	}
}
@lehnenb lehnenb changed the title Warning while setting the document contents Warning when running page.setDocumentContent Sep 22, 2020
@ZekeLu
Copy link
Member

ZekeLu commented May 21, 2021

Moved to chromedp/chromedp#827.

NOTE: Any Issue or Pull Request intended for the cdproto project should be created over https://github.com/chromedp/pdlgen.

Closing.

@ZekeLu ZekeLu closed this as completed May 21, 2021
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