--- title: "Java" url: https://docs.catalyst.zoho.com/en/smartbrowz/help/headless/implementation/function-stack/java/ description: "Connect with a remote browser in the Catalyst cloud environment in a headless mode using an automation library of your choice." last_updated: 2025-10-09T16:11:25Z service: SmartBrowz type: general --- # Connect to Headless With Java Function Stack In this section you will find the required scripts to connect to a headless remote browser using the Java function stack, with a browser automation library of your preference. > **Note:** Puppeteer is not available in the Java function stack. ### Playwright #### Using Playwright Without SmartBrowz ```java package org.example; import com.microsoft.playwright.*; import java.nio.file.Paths; public class PlaywrightJava { public static void main(String[] args) { try (Playwright playwright = Playwright.create()) { try (Browser browser = playwright.chromium().launch()) { BrowserContext context = browser.newContext(); Page page = context.newPage(); page.navigate("http://example.com/""); page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("screenshot.png"))); } } } } ``` #### Using Playwright With SmartBrowz ```java // From inside your Java application public static void main(String[] args) { try (Playwright playwright = Playwright.create()) { BrowserType browserType = playwright.chromium(); //Change browserType.launch with connectOverCDP Browser browser = browserType.connectOverCDP("YOUR_CDP_ENDPOINT"); // The rest of your code remains the same Page page = browser.newPage(); page.navigate("https://www.example.com"); page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("screenshot.png"))); } } ``` > **Note:** Copy the CDP Endpoint present in the console and paste it in line "**8**" when you implement this code. ### Selenium #### Using Selenium Without SmartBrowz ```java import org.apache.commons.io.FileUtils; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import java.io.File; import java.io.IOException; public class ScreenshotDemo { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "path\to\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get("https://demoqa.com"); File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); try { FileUtils.copyFile(screenshot, new File("path\\to\\homePageScreenshot.png")); } catch (IOException e) { System.out.println(e.getMessage()); } driver.close(); } } ``` #### Using Selenium With SmartBrowz ```java // From inside your Java application public static void main() throws MalformedURLException { ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.addArguments("--no-sandbox"); chromeOptions.addArguments("--headless"); chromeOptions.addArguments("--disable-dev-shm-usage"); //Change ChromeDriver with RemoteWebDriver WebDriver driver = new RemoteWebDriver(new URL("YOUR_WEBDRIVER_ENDPOINT"),chromeOptions); // The rest of your code remains the same driver.get("https://www.example.com"); driver.quit(); } ``` > **Note:** Copy the Webdriver Endpoint from the console and paste it in the line "**9**" when you implement this code.