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

Css property being removed, while capturing html #1440

Open
rohit121308 opened this issue Feb 15, 2024 · 3 comments
Open

Css property being removed, while capturing html #1440

rohit121308 opened this issue Feb 15, 2024 · 3 comments

Comments

@rohit121308
Copy link

What versions are you running?

$ go list -m github.com/chromedp/chromedp
github.com/chromedp/chromedp  v0.9.3
$ google-chrome --version
119.0.6045.123
$ go version
go version go1.20.6 linux/amd64

What did you do? Include clear steps.

I am facing an issue with css property. Let me explain the flow, I am getting the style from api , and implementing it inline on the html. This html including the style is being scanned on backend and the html is captured.At the time of html capturing font-size property is being removed.And rest all the other property works fine.

    url := "url_from_where_you want to capture html"
    componentSelector := "#root"
    html := CaptureHtml(url, componentSelector)
    fmt.Println(html)
    return

}

func CaptureHtml(url string, componentSelector string) (template.HTML, error) {
    ctx, cancel := chromedp.NewContext(context.Background())
    defer cancel()
    err := chromedp.Run(ctx, chromedp.Navigate(url), chromedp.WaitVisible(componentSelector, chromedp.ByQuery))
    if err != nil {
        fmt.Println(err)
        return "", err
    }

    // Sleep to ensure the data rendering is complete
    time.Sleep(2 * time.Second)
    var htmlContent string
    // Capture the HTML content of the element containing the rendered API data
    err = chromedp.Run(ctx, chromedp.OuterHTML(componentSelector, &htmlContent, chromedp.NodeVisible))
    if err != nil {
        fmt.Println(err)
    }
    return template.HTML(htmlContent), err
}

What could be the reason of a particular css property being removed?

@kenshaw
Copy link
Member

kenshaw commented Feb 15, 2024

I'm not sure I follow. Is there perhaps a script running that's removing the CSS attribute?

@rohit121308
Copy link
Author

I'm not sure I follow. Is there perhaps a script running that's removing the CSS attribute?

@kenshaw, no there's no script running....

@kenshaw
Copy link
Member

kenshaw commented Feb 15, 2024

I don't really understand then what you mean that the CSS property is being removed. What CSS property, etc. I would suggest using the chromedp.WithDebugf context option to try to get a sense of the messages being sent to/from Chrome. It might shed light on what Chrome is doing. chromedp is fairly simple -- other than setting up high-level API calls to make using chromedp more similar to using the browser's DevTools or how Puppeteer works, chromedp doesn't send any requests to Chrome to alter or modify the content.

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