JxBrowser use experience and document sharing with Chinese translation

After being stuck and tortured by Jcef from time to time, I started the journey of translating JxBrowser documents (not manual translation).

After contacting JxBrowser, I was impressed by its powerful power. I have to say that it is much better than Jcef, so I gave up Jcef directly. The most important point is that it doesn't require so much fancy compilation by JCEF. (It is indeed a good choice for personal projects)

JxBrowser is a cross-platform Java library that allows the integration of Google Chromium-based web browser components into Java Swing / AWT / JavaFX applications. Using JxBrowser, you can embed lightweight Swing/JavaFX components into Java applications to display modern web pages, supporting the latest web standards such as HTML5, CSS3, JavaScript, etc.

This is the description of his official website: JxBrowser can use HTML + CSS + JavaScript to build a Java desktop application UI. This means you can use any modern HTML5 UI toolkit (such as easyui, bootstrap) to build user-friendly Java desktop applications. You can fire Swing/AWT developers, because HTML + CSS + JavaScript developers can build the GUI of Java applications, which greatly reduces the cost of Java project development.

(Swing/AWT development engineer:???)

(Note: Please refer to Google Translate for the above translation content, and its authenticity is not guaranteed)

Get the latest version of JxBrowser: https://jxbrowser-support.teamdev.com/release-notes/2020/v6-24-3.html  (Can't read English? Right-click on Google Chrome and translate into Chinese)

As of the publication date of this article, the latest version of 6.x is 6.24.3 on March 16, 2020.

 

Relevant materials are available in Baidu Cloud Disk (development documents [English original documents, documents with Chinese translation], help documents with Chinese translation (source: https://jxbrowser.support.teamdev.com/support/solutions ), The required Jar (6.24.3), Demo. Because my earliest contact was 6.23.1, the development document with Chinese translation is version 6.23.1): https://pan.baidu.com/s/1P7gMI8- 0Bi8aIDE1d4C0ng  extraction code: k6xp - from Baidu network disk super affiliate v4 sharing

Document CSDN download address: https://download.csdn.net/download/xymmwap/12909790  (Download requires 1 point, friends who can’t run out of CSDN download points can download here, so that I can earn points for occasional needs Download. Thanks!) 

The development document is used to find the usage of the class/method when writing the program, and the help document is used to get started, advance, delete the library and run away. It is recommended to read the help document first and write it according to the example.

Open source personal projects for your reference (you need to add license information to run normally, how to get the license? A lot of Baidu. JxBrowser official website can apply for a 30-day trial), the function is similar to PowerOfLengedJcef (including script management, code template generator, JxBrowser Help Document]:

github:https://github.com/lieyanfeimao/PowerOfLongedJxBrowser.git
码云:https://gitee.com/edadmin/PowerOfLongedJxBrowser.git

Because JxBrowser has already provided a detailed Demo, here I did not write a Demo project like Jcef.

The version of Jxbrowser used in this article is: jxbrowser-6.24.3

Because it is excellent, it is not free. Please find a way to obtain a license. If it can help you, and you have sufficient funds, it is recommended to buy genuine. (Money is a good thing)

advantage:

It perfectly supports the video playback of major video websites, the page is smooth and not stuck (not 100%), supports the interaction between Java and JS, and supports ajax data monitoring. In short, one of the cows.

I really like this way of interaction between JAVA and JS, for example: var a=Java.test();

defect:

Personally feel that it is not friendly to the iframe page operation. It is not convenient to use the developer tool [Debug mode] to connect to the Google server (because the firewall is present, it cannot be connected), the developer tool is very strange, and the operation is not as convenient as the Google browser. . Jcef is better at these two points.

In addition, after a long time of precipitation, JxBrowser will generate a large number of cache/data files under the C drive, which can easily burst the disk. Please refer to the help documentation (Documentation)>Browser Engine>Clearing Cache for processing

Main class introduction

Let me introduce the commonly used classes first, so as not to be confused when writing code (tell me what I have used). Please refer to the development documentation for specific descriptions of related classes.

Browser : The main browser class, which handles browser-related operations, such as executing JS, monitoring events, etc., is a very important class. When you make some settings for the browser, such as monitoring events, forward and backward, etc., you can consult such documents. It is located at: com.teamdev.jxbrowser.chromium

BrowserContext : describes the context of the browser instance. Provide a path to the directory where Chromium data files (such as cookies, history, cache) will be stored, and provide access to context-level functions (such as NetworkService). Two Browser instances with the same BrowserContext will share session cookies and cache files. This class is used when I start multiple applications at the same time, because each application cannot share the same data file directory, so I use it to assign different data file directories to the application.

BrowserPreferences : Browser instance and global library preferences. Set the startup parameters of the browser, etc. Generally set when the program starts, you can also use the setPreferences() method of Browser to set

NetworkService : Provides access to network-level functions. This class is very useful, you can use it to implement operations on network requests. I tried it, and the program is relatively unstable after using it.

Classes beginning with JS: related processing of JS

com.teamdev.jxbrowser.chromium : listener, event

com.teamdev.jxbrowser.chromium.dom : interface for manipulating DOM objects

com.teamdev.jxbrowser.chromium.swing : used for some handler implementation classes under swing, for example, DefaultNetworkDelegate is used to monitor webpage return data

 

There are already various usages of Sao operation in the official Demo, here I will only talk about some commonly used and some pitfalls. (Where is the official Demo? In Baidu Cloud Disk)

Guess you like

Origin blog.csdn.net/xymmwap/article/details/108902853