1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:14:58 +00:00

Browser+LibWebView+WebDriver: Connect WebDriver to WebContent

First, this moves the WebDriver socket to the /tmp/websocket/ directory,
as WebDriver now creates multiple sockets per session. Those sockets are
now created with Core::LocalServer rather than manually setting up the
listening sockets (this was an existing FIXME which resolved some issues
I was hitting with creating a second listening socket).

WebDriver passes both socket paths to Browser via command line. Browser
continues to connect itself via one socket path, then forwards the other
socket path to the WebContent process created by the OOPWV. WebContent
then connects to WebDriver over this path.

WebContent will temporarily set the navigator.webdriver flag to true
after connecting to WebDriver. This will soon be moved to its own IPC to
be sent by WebDriver.
This commit is contained in:
Timothy Flynn 2022-11-08 10:18:11 -05:00 committed by Tim Flynn
parent 6b014489d4
commit 50ae1ad18a
11 changed files with 151 additions and 35 deletions

View file

@ -41,6 +41,7 @@ Vector<String> g_proxies;
HashMap<String, size_t> g_proxy_mappings;
IconBag g_icon_bag;
RefPtr<Browser::WebDriverConnection> g_web_driver_connection;
String g_webdriver_content_ipc_path;
}
@ -68,11 +69,12 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(Core::System::pledge("stdio recvfd sendfd unix fattr cpath rpath wpath proc exec"));
Vector<String> specified_urls;
String webdriver_ipc_path;
String webdriver_browser_ipc_path;
Core::ArgsParser args_parser;
args_parser.add_positional_argument(specified_urls, "URLs to open", "url", Core::ArgsParser::Required::No);
args_parser.add_option(webdriver_ipc_path, "Path to WebDriver IPC", "webdriver", 0, "path");
args_parser.add_option(webdriver_browser_ipc_path, "Path to WebDriver IPC file for Browser", "webdriver-browser-path", 0, "path");
args_parser.add_option(Browser::g_webdriver_content_ipc_path, "Path to WebDriver IPC for WebContent", "webdriver-content-path", 0, "path");
args_parser.parse(arguments);
@ -87,9 +89,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(Desktop::Launcher::add_allowed_url(URL::create_with_file_scheme(Core::StandardPaths::downloads_directory())));
TRY(Desktop::Launcher::seal_allowlist());
if (!webdriver_ipc_path.is_empty()) {
if (!webdriver_browser_ipc_path.is_empty()) {
specified_urls.empend("about:blank");
TRY(Core::System::unveil(webdriver_ipc_path.view(), "rw"sv));
TRY(Core::System::unveil(webdriver_browser_ipc_path, "rw"sv));
}
TRY(Core::System::unveil("/sys/kernel/processes", "r"));
@ -147,13 +149,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
Browser::CookieJar cookie_jar;
auto window = Browser::BrowserWindow::construct(cookie_jar, first_url);
if (!webdriver_ipc_path.is_empty()) {
Browser::g_web_driver_connection = TRY(Browser::WebDriverConnection::connect_to_webdriver(window, webdriver_ipc_path));
// The first tab is created with the BrowserWindow above, so we have to do this
// manually once after establishing the connection.
window->active_tab().enable_webdriver_mode();
}
if (!webdriver_browser_ipc_path.is_empty())
Browser::g_web_driver_connection = TRY(Browser::WebDriverConnection::connect_to_webdriver(window, webdriver_browser_ipc_path));
auto content_filters_watcher = TRY(Core::FileWatcher::create());
content_filters_watcher->on_change = [&](Core::FileWatcherEvent const&) {