1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 15:27:35 +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:
Sam Atkins 2022-10-12 10:50:33 +01:00 committed by Linus Groh
parent ec9c11667f
commit 8c0f1da9f7
6 changed files with 129 additions and 1 deletions

View 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
*/
#pragma once
#include "BrowserWindow.h"
#include <AK/Error.h>
#include <AK/String.h>
#include <Applications/Browser/WebDriverSessionClientEndpoint.h>
#include <Applications/Browser/WebDriverSessionServerEndpoint.h>
#include <LibCore/LocalServer.h>
#include <LibGUI/Application.h>
#include <LibIPC/ConnectionToServer.h>
#include <unistd.h>
namespace Browser {
class WebDriverConnection final
: public IPC::ConnectionToServer<WebDriverSessionClientEndpoint, WebDriverSessionServerEndpoint> {
C_OBJECT_ABSTRACT(WebDriverConnection)
public:
static ErrorOr<NonnullRefPtr<WebDriverConnection>> connect_to_webdriver(NonnullRefPtr<BrowserWindow> browser_window, String path)
{
dbgln("Trying to connect to {}", path);
auto result = TRY(Core::Stream::LocalSocket::connect(path));
dbgln("Connected to WebDriver");
return TRY(adopt_nonnull_ref_or_enomem(new (nothrow) WebDriverConnection(move(result), browser_window)));
}
virtual ~WebDriverConnection() = default;
virtual void die() override { }
virtual void quit() override;
virtual Messages::WebDriverSessionClient::GetUrlResponse get_url() override;
virtual void set_url(AK::URL const& url) override;
virtual Messages::WebDriverSessionClient::GetTitleResponse get_title() override;
private:
WebDriverConnection(NonnullOwnPtr<Core::Stream::LocalSocket> socket, NonnullRefPtr<BrowserWindow> browser_window);
WeakPtr<BrowserWindow> m_browser_window;
};
}