Good afternoon! Earlier, you sent an implementation option.
public static void main(String[] args) throws Exception {
ChromiumBrowser.earlyInit();
final IndependentBrowser browser = (IndependentBrowser) ChromiumBrowser.windowless(URL);
// Wait for browser creation, then schedule screenshot in separate thread
browser.isCreated().thenRun(() -> {
Executors.newSingleThreadScheduledExecutor().schedule(() -> {
try {
//.....
byte[] screenshotBase64 = browser.captureScreenshot().join();
byte[] pngBytes = Base64.getDecoder().decode(screenshotBase64);
Path screenshotPath = Paths.get("screenshot.png").toAbsolutePath();
Files.write(screenshotPath, pngBytes);
System.out.println("Screenshot saved to: " + screenshotPath);
browser.close();
} catch (Exception e) {
System.err.println("Screenshot failed: " + e.getMessage());
e.printStackTrace();
browser.close();
}
}, 5, TimeUnit.SECONDS); // Wait 5 seconds for page load
});
ChromiumBrowser.startBrowsers(); //The main thread is completely blocked and when calling the close method browser.close(), nothing happens.
//It will never be fulfilled...(((
}
But its problem is that it leads to the shutdown of the application after performing all the actions, and I would like it to continue after closing the browser, but even when calling the close method of the browser, execution does not continue.
Good afternoon! Earlier, you sent an implementation option.
But its problem is that it leads to the shutdown of the application after performing all the actions, and I would like it to continue after closing the browser, but even when calling the close method of the browser, execution does not continue.