mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:17:34 +00:00
Browser: Add a basic WebDriver API
This adds a new option "--webdriver" that opens a local unix socket in /tmp/browser_{pid} which the WebDriver server can use to send commands to the Browser instance. Co-authored-by: Florent Castelli <florent.castelli@gmail.com>
This commit is contained in:
parent
ec9c11667f
commit
8c0f1da9f7
6 changed files with 129 additions and 1 deletions
49
Userland/Applications/Browser/WebDriverConnection.cpp
Normal file
49
Userland/Applications/Browser/WebDriverConnection.cpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Florent Castelli <florent.castelli@gmail.com>
|
||||
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "WebDriverConnection.h"
|
||||
#include "BrowserWindow.h"
|
||||
|
||||
namespace Browser {
|
||||
|
||||
WebDriverConnection::WebDriverConnection(NonnullOwnPtr<Core::Stream::LocalSocket> socket, NonnullRefPtr<BrowserWindow> browser_window)
|
||||
: IPC::ConnectionToServer<WebDriverSessionClientEndpoint, WebDriverSessionServerEndpoint>(*this, move(socket))
|
||||
, m_browser_window(move(browser_window))
|
||||
{
|
||||
}
|
||||
|
||||
void WebDriverConnection::quit()
|
||||
{
|
||||
dbgln("WebDriverConnection: quit");
|
||||
if (auto browser_window = m_browser_window.strong_ref())
|
||||
browser_window->close();
|
||||
}
|
||||
|
||||
Messages::WebDriverSessionClient::GetUrlResponse WebDriverConnection::get_url()
|
||||
{
|
||||
dbgln("WebDriverConnection: get_url");
|
||||
if (auto browser_window = m_browser_window.strong_ref())
|
||||
return { browser_window->active_tab().url() };
|
||||
return { URL("") };
|
||||
}
|
||||
|
||||
void WebDriverConnection::set_url(AK::URL const& url)
|
||||
{
|
||||
dbgln("WebDriverConnection: set_url {}", url);
|
||||
if (auto browser_window = m_browser_window.strong_ref())
|
||||
browser_window->active_tab().load(url);
|
||||
}
|
||||
|
||||
Messages::WebDriverSessionClient::GetTitleResponse WebDriverConnection::get_title()
|
||||
{
|
||||
dbgln("WebDriverConnection: get_title");
|
||||
if (auto browser_window = m_browser_window.strong_ref())
|
||||
return { browser_window->active_tab().title() };
|
||||
return { "" };
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue