Selenium (WebDriver)
Use Lightpanda with Selenium over classic WebDriver (HTTP) or WebDriver BiDi (WebSocket). A session created the normal Selenium way can be driven with classic commands (driver.get(), find_element(), click(), send_keys(), execute_script(), …), and also over BiDi when it asks for the webSocketUrl capability.
WebDriver support, classic and BiDi, is new and doesn’t cover the full specs yet. If a command your scripts need is missing, open an issue .
Start Lightpanda with the webdriver protocol enabled (find all options in the serve command reference):
lightpanda serve --host 127.0.0.1 --port 9222 --protocol webdriverThis example drives the browser over BiDi: request a BiDi session by setting the webSocketUrl capability to true (browserName can be any value; Lightpanda reports itself back regardless). Without it, the session uses classic WebDriver commands (driver.get(), findElement(), …).
JavaScript
npm install selenium-webdriver'use strict'
import { Builder, Capabilities } from 'selenium-webdriver'
import { BrowsingContext } from 'selenium-webdriver/bidi/generated/browsing_context.js'
import { Script } from 'selenium-webdriver/bidi/generated/script.js'
const caps = new Capabilities()
caps.set('browserName', 'lightpanda')
caps.set('webSocketUrl', true)
const driver = await new Builder()
.usingServer('http://127.0.0.1:9222')
.withCapabilities(caps)
.build()
const browsingContext = await BrowsingContext.create(driver)
const script = await Script.create(driver)
const { context } = await browsingContext.create({ type: 'tab' })
await browsingContext.navigate({ context, url: 'https://wikipedia.com/', wait: 'complete' })
const title = await script.evaluate({
expression: 'document.title',
target: { context },
awaitPromise: false,
})
console.log(title.result.value)
await browsingContext.close({ context })
await driver.quit()