hardkoded / puppeteer-sharp

Headless Chrome .NET API
https://www.puppeteersharp.com
MIT License
3.38k stars 441 forks source link

Is there any way to pass an html string of a raw page to have puppeteer render the full page with all js? #1322

Closed sjdirect closed 4 years ago

sjdirect commented 4 years ago

I am the author of Abot/AbotX (c# web crawler). I wanted to create another js rendering impl using chrome headless (have a working impl for phantomjs) Currently phantomjs allows me to pass raw html to it and it will do the final rendering (without having to rerequest the page again). This allows me to offer javascript rendering as an additional step in the current crawl process. Can Puppeteer/chromeheadless do the same? Not finding anything in the docs. The worst case looks to be passing the path for a ""file:///""?

Looks like a cool project, thanks for building it out!

kblok commented 4 years ago

Hey @sjdirect.

You can inject content using SetContentAsync. You can take a look at some tests here.

You can also use AddScriptTag to inject javascript to an existing page.

ahmadalli commented 4 years ago

@sjdirect how about going to data:text/html,{html}? (try it on your browser. e.g. go to data:text/html,<h1>hello</h1>

kblok commented 4 years ago

Closed due to inactivity. Feel free to reopen it if needed.