The webdriverbidi library provides an interface for interacting with web browsers through the WebDriver BiDi (Bidirectional) protocol. This library allows you to create and manage WebDriver sessions, send commands, and handle responses asynchronously through WebSockets.
- Create and manage WebDriver BiDi sessions
- Send commands
- Handle events asynchronously
- Rust and Cargo installed
- A WebDriver server that supports the BiDi protocol
Add the following to your Cargo.toml
(the example below will also require tokio with full features):
[dependencies]
webdriverbidi = "0.1.13"
Start a WebDriver BiDi compliant server
$ geckodriver --host=localhost --port=4444
Create a new Rust project and add the following code to src/main.rs
:
use tokio;
use tokio::time;
// --------------------------------------------------
use webdriverbidi::remote::browsing_context::{
GetTreeParameters, NavigateParameters, ReadinessState,
};
use webdriverbidi::session::WebDriverBiDiSession;
use webdriverbidi::webdriver::capabilities::CapabilitiesRequest;
// --------------------------------------------------
async fn sleep(secs: u64) {
time::sleep(time::Duration::from_secs(secs)).await
}
#[tokio::main]
async fn main() {
// Initialize a new WebDriver BiDi session and start it
let host = String::from("localhost");
let port = 4444;
let capabilities = CapabilitiesRequest::default();
let mut session = WebDriverBiDiSession::new(host, port, capabilities);
session.start().await.expect("Failed to start session");
// Get the browsing context tree
let get_tree_params = GetTreeParameters::new(None, None);
let get_tree_rslt = session
.browsing_context_get_tree(get_tree_params)
.await
.expect("Failed to get browsing context tree");
// Navigate to rust-lang.org
let navigate_params = NavigateParameters::new(
get_tree_rslt.contexts[0].context.clone(),
"https://www.rust-lang.org/".to_string(),
Some(ReadinessState::Complete),
);
session
.browsing_context_navigate(navigate_params)
.await
.expect("Failed to navigate");
sleep(2).await;
// Close the session
session.close().await.expect("Failed to close session");
}
- session.CapabilitiesRequest
- session.CapabilityRequest
- session.ProxyConfiguration
- session.UserPromptHandler
- session.UserPromptHandlerType
- session.Subscription
- session.SubscriptionRequest
- session.UnsubscribeByIDRequest
- session.UnsubscribeByAttributesRequest
- session.status
- session.new
- session.end
- session.subscribe
- session.unsubscribe
- browser.ClientWindow
- browser.ClientWindowInfo
- browser.UserContext
- browser.UserContextInfo
- browser.close
- browser.createUserContext
- browser.getClientWindows
- browser.getUserContexts
- browser.removeUserContext
- browser.setClientWindowState
- browsingContext.BrowsingContext
- browsingContext.Info
- browsingContext.Locator
- browsingContext.Navigation
- browsingContext.NavigationInfo
- browsingContext.ReadinessState
- browsingContext.UserPromptType
- browsingContext.activate
- browsingContext.captureScreenshot
- browsingContext.close
- browsingContext.create
- browsingContext.getTree
- browsingContext.handleUserPrompt
- browsingContext.locateNodes
- browsingContext.navigate
- browsingContext.print
- browsingContext.reload
- browsingContext.setViewport
- browsingContext.traverseHistory
- browsingContext.contextCreated
- browsingContext.contextDestroyed
- browsingContext.navigationStarted
- browsingContext.fragmentNavigated
- browsingContext.historyUpdated
- browsingContext.domContentLoaded
- browsingContext.load
- browsingContext.downloadWillBegin
- browsingContext.navigationAborted
- browsingContext.navigationFailed
- browsingContext.userPromptClosed
- browsingContext.userPromptOpened
- network.AuthChallenge
- network.AuthCredentials
- network.BaseParameters
- network.BytesValue
- network.Cookie
- network.CookieHeader
- network.FetchTimingInfo
- network.Header
- network.Initiator
- network.Intercept
- network.Request
- network.RequestData
- network.ResponseContent
- network.ResponseData
- network.SetCookieHeader
- network.UrlPattern
- network.addIntercept
- network.continueRequest
- network.continueResponse
- network.continueWithAuth
- network.failRequest
- network.provideResponse
- network.removeIntercept
- network.setCacheBehavior
- network.authRequired
- network.beforeRequestSent
- network.fetchError
- network.responseCompleted
- network.responseStarted
- script.Channel
- script.ChannelValue
- script.EvaluateResult
- script.ExceptionDetails
- script.Handle
- script.InternalId
- script.LocalValue
- script.PreloadScript
- script.Realm
- script.PrimitiveProtocolValue
- script.RealmInfo
- script.RealmType
- script.RemoteReference
- script.RemoteValue
- script.ResultOwnership
- script.SerializationOptions
- script.SharedId
- script.StackFrame
- script.StackTrace
- script.Source
- script.Target
- script.addPreloadScript
- script.disown
- script.callFunction
- script.evaluate
- script.getRealms
- script.removePreloadScript
- script.message
- script.realmCreated
- script.realmDestroyed
- storage.PartitionKey
- storage.getCookies
- storage.setCookie
- storage.deleteCookies
- log.LogEntry
- log.entryAdded
- input.ElementOrigin
- input.performActions
- input.releaseActions
- input.setFiles
- webExtension.Extension
- webExtension.install
- webExtension.uninstall
Contributions are welcome! Please open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.