diff --git a/addOns/selenium/CHANGELOG.md b/addOns/selenium/CHANGELOG.md index 2750096b4c..3d2c60e898 100644 --- a/addOns/selenium/CHANGELOG.md +++ b/addOns/selenium/CHANGELOG.md @@ -5,7 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## Unreleased +### Added +- Allow to log browser's `console.log`, done at DEBUG level with the name `org.zaproxy.webdriver`. +### Changed +- Use WebDriver BiDi with Chrome. ## [15.32.0] - 2025-01-10 ### Changed diff --git a/addOns/selenium/src/main/java/org/zaproxy/zap/extension/selenium/ExtensionSelenium.java b/addOns/selenium/src/main/java/org/zaproxy/zap/extension/selenium/ExtensionSelenium.java index 116b562823..9985f7c175 100644 --- a/addOns/selenium/src/main/java/org/zaproxy/zap/extension/selenium/ExtensionSelenium.java +++ b/addOns/selenium/src/main/java/org/zaproxy/zap/extension/selenium/ExtensionSelenium.java @@ -58,6 +58,7 @@ import org.openqa.selenium.htmlunit.HtmlUnitDriver; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.safari.SafariDriver; import org.openqa.selenium.safari.SafariOptions; import org.parosproxy.paros.Constant; @@ -92,6 +93,10 @@ public class ExtensionSelenium extends ExtensionAdaptor { private static final Logger LOGGER = LogManager.getLogger(ExtensionSelenium.class); + private static final Logger WEBDRIVER_LOGGER = LogManager.getLogger("org.zaproxy.webdriver"); + + private static final String BIDI_CAPABILITIY = "webSocketUrl"; + private static final List> EXTENSION_DEPENDENCIES = List.of(ExtensionNetwork.class); @@ -1037,6 +1042,11 @@ private static void addChromeExtensions(ChromeOptions options) { .collect(Collectors.toList())); } + private static RemoteWebDriver configureDriver(RemoteWebDriver driver) { + driver.script().addConsoleMessageHandler(e -> WEBDRIVER_LOGGER.debug(e.getText())); + return driver; + } + private static WebDriver getWebDriverImpl( int requester, Browser browser, @@ -1048,6 +1058,7 @@ private static WebDriver getWebDriverImpl( case CHROME: case CHROME_HEADLESS: ChromeOptions chromeOptions = new ChromeOptions(); + chromeOptions.setCapability(BIDI_CAPABILITIY, true); if (enableExtensions) { addChromeExtensions(chromeOptions); } @@ -1064,12 +1075,12 @@ private static WebDriver getWebDriverImpl( addChromeArguments(chromeOptions); consumer.accept(chromeOptions); - return new ChromeDriver(chromeOptions); + return configureDriver(new ChromeDriver(chromeOptions)); case FIREFOX: case FIREFOX_HEADLESS: FirefoxOptions firefoxOptions = new FirefoxOptions(); // Use WebDriver BiDi - firefoxOptions.setCapability("webSocketUrl", true); + firefoxOptions.setCapability(BIDI_CAPABILITIY, true); // Force the use of just BiDi, should not be required once Selenium stops // adding the preference https://github.com/SeleniumHQ/selenium/issues/14885 firefoxOptions.addPreference("remote.active-protocols", "1"); @@ -1141,7 +1152,7 @@ private static WebDriver getWebDriverImpl( if (enableExtensions) { addFirefoxExtensions(driver); } - return driver; + return configureDriver(driver); case HTML_UNIT: DesiredCapabilities htmlunitCapabilities = new DesiredCapabilities(); setCommonOptions(htmlunitCapabilities, proxyAddress, proxyPort);