Confirmation on the necessary features

Having problems with building or using the JCEF Java binding? Ask your questions here.

Confirmation on the necessary features

Postby Mindaugas » Fri Dec 21, 2018 11:21 am

Hi guys,

I want to automate rendering of some internal websites for reporting reasons.
More concretely the steps would be:
- navigate to an appropriate website;
- authenticate;
- navigate to the appropriate page;
- detect a particular tag (by ID or by class name);
- render it (or render the whole page and then extract the necessary part);
- create a .png or .jpeg and
- push it as a file to an external service for reporting.

I know I can do this with phantomJS, but I want to create a plugin for Jenkins
and the language for creating that is JAVA. It would be possible to write a wrapper
around phantomJS in JAVA, but maybe I could bypass that and use a webkit based
JAVA library. Which would be a more homogeneous approach.

QUESTION: is it possible to take screenshots headlesly in JCEF for particular parts of a document?
How would one go about doing that.
Mindaugas
Newbie
 
Posts: 3
Joined: Fri Dec 21, 2018 11:13 am

Re: Confirmation on the necessary features

Postby Mindaugas » Fri Dec 28, 2018 10:41 am

Let me simplify the question a bit - is JCEF capable of taking a screenshot of a fully rendered DOM element?
Example using chrome headless: https://gist.github.com/malyw/b4e8284e4 ... a9b0263743

Appreciate it!
Thank you
Mindaugas
Newbie
 
Posts: 3
Joined: Fri Dec 21, 2018 11:13 am

Re: Confirmation on the necessary features

Postby magreenblatt » Fri Dec 28, 2018 12:33 pm

What you’re seeking is possible, but you will need to write code (Java and/or JavaScript) to do it.
magreenblatt
Site Admin
 
Posts: 12384
Joined: Fri May 29, 2009 6:57 pm

Re: Confirmation on the necessary features

Postby Mindaugas » Mon Dec 31, 2018 8:33 am

magreenblatt wrote:What you’re seeking is possible, but you will need to write code (Java and/or JavaScript) to do it.


Thanks a lot for the reply, I really appreciate it!

TL;DR:
I have a concern that types like CefDOMNode are not available in JCEF (i) and that I can't return anything from executeJAvaScript() methods as they all are void (ii).
How would I go about obtaining the DOM element into memory and then creating a PNG from it? Do I need to extend the JCEF wrapper classes?

LONG VERSION:
The general program flow would be:
- Launch CEF Browser (CefApp(), createBrowser(), loadURL()) w/o rendering it in a JFrame - the goal here is headless rendering;
- Navigate to the appropriate page / open a modal view (with getMainFrame(), ExecuteJavaScript()).
- Obtain the DOM node of interest - the one that I want to pring( ExecuteJavaScript(), onLoadEnd() or onLoadingStateChange()).
... and this is where I got stuck. The Chromium DOM API is read-only which should be enough for my usecase (printing a specific fully-rendered element).
But I'm not sure how to obtain it (i) what datatype should I save it in (ii) and create a screenshot from it(iii).

I read that I should use Window Binding or Extensions - is that correct?
magreenblatt wrote:In order to return values from JS to the client application consider using Window Binding or Extensions.

I also can't find the "CefDOMVisitor, CefDOMDocument, CefDOMNode, CefDOMEvent and CefDOMEventListener" types in JCEF - so it is not clear how would one go about saving the DOM node into memory and then creating a screenshot out of it.
Mindaugas
Newbie
 
Posts: 3
Joined: Fri Dec 21, 2018 11:13 am

Re: Confirmation on the necessary features

Postby magreenblatt » Mon Dec 31, 2018 9:30 am

The CefDOM classes are not available in Java because Java does not run in the renderer process. You can use ExecuteJavaScript and CefMessageRouter to communicate between Java running in the main process and JavaScript running in the renderer process. You can find examples in the JCEF detailed app.
magreenblatt
Site Admin
 
Posts: 12384
Joined: Fri May 29, 2009 6:57 pm

Re: Confirmation on the necessary features

Postby magreenblatt » Mon Dec 31, 2018 9:33 am

To get a PNG from a dom element you can use JavaScript, DevTools remote debugging protocol, or customize the JCEF off-screen rendering implementation.
magreenblatt
Site Admin
 
Posts: 12384
Joined: Fri May 29, 2009 6:57 pm


Return to JCEF Forum

Who is online

Users browsing this forum: No registered users and 21 guests