Use Optional::valueOr() instead of Optional::value_or()
[WebKit-https.git] / Source / WebDriver / WebDriverService.cpp
index 3934070..e526882 100644 (file)
@@ -45,14 +45,16 @@ WebDriverService::WebDriverService()
 static void printUsageStatement(const char* programName)
 {
     printf("Usage: %s options\n", programName);
-    printf("  -h, --help                Prints this help message\n");
+    printf("  -h,        --help         Prints this help message\n");
     printf("  -p <port>, --port=<port>  Port number the driver will use\n");
+    printf("             --host=<host>  Host IP the driver will use, or either 'local' or 'all' (default: 'local')");
     printf("\n");
 }
 
 int WebDriverService::run(int argc, char** argv)
 {
     String portString;
+    Optional<String> host;
     for (int i = 1 ; i < argc; ++i) {
         const char* arg = argv[i];
         if (!strcmp(arg, "-h") || !strcmp(arg, "--help")) {
@@ -74,6 +76,12 @@ int WebDriverService::run(int argc, char** argv)
             portString = String(arg + portStrLength);
             continue;
         }
+
+        static const unsigned hostStrLength = strlen("--host=");
+        if (!strncmp(arg, "--host=", hostStrLength) && !host) {
+            host = String(arg + hostStrLength);
+            continue;
+        }
     }
 
     if (portString.isNull()) {
@@ -90,7 +98,7 @@ int WebDriverService::run(int argc, char** argv)
 
     RunLoop::initializeMainRunLoop();
 
-    if (!m_server.listen(port))
+    if (!m_server.listen(host, port))
         return EXIT_FAILURE;
 
     RunLoop::run();
@@ -122,6 +130,9 @@ const WebDriverService::Command WebDriverService::s_commands[] = {
     { HTTPMethod::Post, "/session/$sessionId/frame/parent", &WebDriverService::switchToParentFrame },
     { HTTPMethod::Get, "/session/$sessionId/window/rect", &WebDriverService::getWindowRect },
     { HTTPMethod::Post, "/session/$sessionId/window/rect", &WebDriverService::setWindowRect },
+    { HTTPMethod::Post, "/session/$sessionId/window/maximize", &WebDriverService::maximizeWindow },
+    { HTTPMethod::Post, "/session/$sessionId/window/minimize", &WebDriverService::minimizeWindow },
+    { HTTPMethod::Post, "/session/$sessionId/window/fullscreen", &WebDriverService::fullscreenWindow },
 
     { HTTPMethod::Post, "/session/$sessionId/element", &WebDriverService::findElement },
     { HTTPMethod::Post, "/session/$sessionId/elements", &WebDriverService::findElements },
@@ -151,6 +162,9 @@ const WebDriverService::Command WebDriverService::s_commands[] = {
     { HTTPMethod::Delete, "/session/$sessionId/cookie/$name", &WebDriverService::deleteCookie },
     { HTTPMethod::Delete, "/session/$sessionId/cookie", &WebDriverService::deleteAllCookies },
 
+    { HTTPMethod::Post, "/session/$sessionId/actions", &WebDriverService::performActions },
+    { HTTPMethod::Delete, "/session/$sessionId/actions", &WebDriverService::releaseActions },
+
     { HTTPMethod::Post, "/session/$sessionId/alert/dismiss", &WebDriverService::dismissAlert },
     { HTTPMethod::Post, "/session/$sessionId/alert/accept", &WebDriverService::acceptAlert },
     { HTTPMethod::Get, "/session/$sessionId/alert/text", &WebDriverService::getAlertText },
@@ -163,7 +177,7 @@ const WebDriverService::Command WebDriverService::s_commands[] = {
     { HTTPMethod::Get, "/session/$sessionId/element/$elementId/displayed", &WebDriverService::isElementDisplayed },
 };
 
-std::optional<WebDriverService::HTTPMethod> WebDriverService::toCommandHTTPMethod(const String& method)
+Optional<WebDriverService::HTTPMethod> WebDriverService::toCommandHTTPMethod(const String& method)
 {
     auto lowerCaseMethod = method.convertToASCIILowercase();
     if (lowerCaseMethod == "get")
@@ -173,7 +187,7 @@ std::optional<WebDriverService::HTTPMethod> WebDriverService::toCommandHTTPMetho
     if (lowerCaseMethod == "delete")
         return WebDriverService::HTTPMethod::Delete;
 
-    return std::nullopt;
+    return WTF::nullopt;
 }
 
 bool WebDriverService::findCommand(HTTPMethod method, const String& path, CommandHandler* handler, HashMap<String, String>& parameters)
@@ -183,10 +197,8 @@ bool WebDriverService::findCommand(HTTPMethod method, const String& path, Comman
         if (s_commands[i].method != method)
             continue;
 
-        Vector<String> pathTokens;
-        path.split("/", pathTokens);
-        Vector<String> commandTokens;
-        String::fromUTF8(s_commands[i].uriTemplate).split("/", commandTokens);
+        Vector<String> pathTokens = path.split('/');
+        Vector<String> commandTokens = String::fromUTF8(s_commands[i].uriTemplate).split('/');
         if (pathTokens.size() != commandTokens.size())
             continue;
 
@@ -255,12 +267,12 @@ void WebDriverService::sendResponse(Function<void (HTTPRequestHandler::Response&
         // https://w3c.github.io/webdriver/webdriver-spec.html#dfn-send-an-error
         // Let body be a new JSON Object initialised with the following properties: "error", "message", "stacktrace".
         auto errorObject = JSON::Object::create();
-        errorObject->setString(ASCIILiteral("error"), result.errorString());
-        errorObject->setString(ASCIILiteral("message"), result.errorMessage().value_or(emptyString()));
-        errorObject->setString(ASCIILiteral("stacktrace"), emptyString());
+        errorObject->setString("error"_s, result.errorString());
+        errorObject->setString("message"_s, result.errorMessage().valueOr(emptyString()));
+        errorObject->setString("stacktrace"_s, emptyString());
         // If the error data dictionary contains any entries, set the "data" field on body to a new JSON Object populated with the dictionary.
         if (auto& additionalData = result.additionalErrorData())
-            errorObject->setObject(ASCIILiteral("data"), RefPtr<JSON::Object> { additionalData });
+            errorObject->setObject("data"_s, RefPtr<JSON::Object> { additionalData });
         // Send a response with status and body as arguments.
         resultValue = WTFMove(errorObject);
     } else if (auto value = result.result())
@@ -271,42 +283,42 @@ void WebDriverService::sendResponse(Function<void (HTTPRequestHandler::Response&
     // When required to send a response.
     // https://w3c.github.io/webdriver/webdriver-spec.html#dfn-send-a-response
     RefPtr<JSON::Object> responseObject = JSON::Object::create();
-    responseObject->setValue(ASCIILiteral("value"), WTFMove(resultValue));
-    replyHandler({ result.httpStatusCode(), responseObject->toJSONString().utf8(), ASCIILiteral("application/json; charset=utf-8") });
+    responseObject->setValue("value"_s, WTFMove(resultValue));
+    replyHandler({ result.httpStatusCode(), responseObject->toJSONString().utf8(), "application/json; charset=utf-8"_s });
 }
 
-static std::optional<double> valueAsNumberInRange(const JSON::Value& value, double minAllowed = 0, double maxAllowed = std::numeric_limits<int>::max())
+static Optional<double> valueAsNumberInRange(const JSON::Value& value, double minAllowed = 0, double maxAllowed = std::numeric_limits<int>::max())
 {
     double number;
     if (!value.asDouble(number))
-        return std::nullopt;
+        return WTF::nullopt;
 
     if (std::isnan(number) || std::isinf(number))
-        return std::nullopt;
+        return WTF::nullopt;
 
     if (number < minAllowed || number > maxAllowed)
-        return std::nullopt;
+        return WTF::nullopt;
 
     return number;
 }
 
-static std::optional<uint64_t> unsignedValue(JSON::Value& value)
+static Optional<uint64_t> unsignedValue(JSON::Value& value)
 {
     auto number = valueAsNumberInRange(value, 0, maxSafeInteger);
     if (!number)
-        return std::nullopt;
+        return WTF::nullopt;
 
     auto intValue = static_cast<uint64_t>(number.value());
     // If the contained value is a double, bail in case it doesn't match the integer
     // value, i.e. if the double value was not originally in integer form.
     // https://w3c.github.io/webdriver/webdriver-spec.html#dfn-integer
     if (number.value() != intValue)
-        return std::nullopt;
+        return WTF::nullopt;
 
     return intValue;
 }
 
-static std::optional<Timeouts> deserializeTimeouts(JSON::Object& timeoutsObject)
+static Optional<Timeouts> deserializeTimeouts(JSON::Object& timeoutsObject)
 {
     // §8.5 Set Timeouts.
     // https://w3c.github.io/webdriver/webdriver-spec.html#dfn-deserialize-as-a-timeout
@@ -319,7 +331,7 @@ static std::optional<Timeouts> deserializeTimeouts(JSON::Object& timeoutsObject)
         // If value is not an integer, or it is less than 0 or greater than the maximum safe integer, return error with error code invalid argument.
         auto timeoutMS = unsignedValue(*it->value);
         if (!timeoutMS)
-            return std::nullopt;
+            return WTF::nullopt;
 
         if (it->key == "script")
             timeouts.script = Seconds::fromMilliseconds(timeoutMS.value());
@@ -328,12 +340,12 @@ static std::optional<Timeouts> deserializeTimeouts(JSON::Object& timeoutsObject)
         else if (it->key == "implicit")
             timeouts.implicit = Seconds::fromMilliseconds(timeoutMS.value());
         else
-            return std::nullopt;
+            return WTF::nullopt;
     }
     return timeouts;
 }
 
-static std::optional<PageLoadStrategy> deserializePageLoadStrategy(const String& pageLoadStrategy)
+static Optional<PageLoadStrategy> deserializePageLoadStrategy(const String& pageLoadStrategy)
 {
     if (pageLoadStrategy == "none")
         return PageLoadStrategy::None;
@@ -341,10 +353,10 @@ static std::optional<PageLoadStrategy> deserializePageLoadStrategy(const String&
         return PageLoadStrategy::Normal;
     if (pageLoadStrategy == "eager")
         return PageLoadStrategy::Eager;
-    return std::nullopt;
+    return WTF::nullopt;
 }
 
-static std::optional<UnhandledPromptBehavior> deserializeUnhandledPromptBehavior(const String& unhandledPromptBehavior)
+static Optional<UnhandledPromptBehavior> deserializeUnhandledPromptBehavior(const String& unhandledPromptBehavior)
 {
     if (unhandledPromptBehavior == "dismiss")
         return UnhandledPromptBehavior::Dismiss;
@@ -356,35 +368,35 @@ static std::optional<UnhandledPromptBehavior> deserializeUnhandledPromptBehavior
         return UnhandledPromptBehavior::AcceptAndNotify;
     if (unhandledPromptBehavior == "ignore")
         return UnhandledPromptBehavior::Ignore;
-    return std::nullopt;
+    return WTF::nullopt;
 }
 
 void WebDriverService::parseCapabilities(const JSON::Object& matchedCapabilities, Capabilities& capabilities) const
 {
     // Matched capabilities have already been validated.
     bool acceptInsecureCerts;
-    if (matchedCapabilities.getBoolean(ASCIILiteral("acceptInsecureCerts"), acceptInsecureCerts))
+    if (matchedCapabilities.getBoolean("acceptInsecureCerts"_s, acceptInsecureCerts))
         capabilities.acceptInsecureCerts = acceptInsecureCerts;
     bool setWindowRect;
-    if (matchedCapabilities.getBoolean(ASCIILiteral("setWindowRect"), setWindowRect))
+    if (matchedCapabilities.getBoolean("setWindowRect"_s, setWindowRect))
         capabilities.setWindowRect = setWindowRect;
     String browserName;
-    if (matchedCapabilities.getString(ASCIILiteral("browserName"), browserName))
+    if (matchedCapabilities.getString("browserName"_s, browserName))
         capabilities.browserName = browserName;
     String browserVersion;
-    if (matchedCapabilities.getString(ASCIILiteral("browserVersion"), browserVersion))
+    if (matchedCapabilities.getString("browserVersion"_s, browserVersion))
         capabilities.browserVersion = browserVersion;
     String platformName;
-    if (matchedCapabilities.getString(ASCIILiteral("platformName"), platformName))
+    if (matchedCapabilities.getString("platformName"_s, platformName))
         capabilities.platformName = platformName;
     RefPtr<JSON::Object> timeouts;
-    if (matchedCapabilities.getObject(ASCIILiteral("timeouts"), timeouts))
+    if (matchedCapabilities.getObject("timeouts"_s, timeouts))
         capabilities.timeouts = deserializeTimeouts(*timeouts);
     String pageLoadStrategy;
-    if (matchedCapabilities.getString(ASCIILiteral("pageLoadStrategy"), pageLoadStrategy))
+    if (matchedCapabilities.getString("pageLoadStrategy"_s, pageLoadStrategy))
         capabilities.pageLoadStrategy = deserializePageLoadStrategy(pageLoadStrategy);
     String unhandledPromptBehavior;
-    if (matchedCapabilities.getString(ASCIILiteral("unhandledPromptBehavior"), unhandledPromptBehavior))
+    if (matchedCapabilities.getString("unhandledPromptBehavior"_s, unhandledPromptBehavior))
         capabilities.unhandledPromptBehavior = deserializeUnhandledPromptBehavior(unhandledPromptBehavior);
     platformParseCapabilities(matchedCapabilities, capabilities);
 }
@@ -392,7 +404,7 @@ void WebDriverService::parseCapabilities(const JSON::Object& matchedCapabilities
 bool WebDriverService::findSessionOrCompleteWithError(JSON::Object& parameters, Function<void (CommandResult&&)>& completionHandler)
 {
     String sessionID;
-    if (!parameters.getString(ASCIILiteral("sessionId"), sessionID)) {
+    if (!parameters.getString("sessionId"_s, sessionID)) {
         completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument));
         return false;
     }
@@ -477,15 +489,15 @@ RefPtr<JSON::Object> WebDriverService::matchCapabilities(const JSON::Object& mer
     // so we only reject the known capabilities that don't match.
     RefPtr<JSON::Object> matchedCapabilities = JSON::Object::create();
     if (platformCapabilities.browserName)
-        matchedCapabilities->setString(ASCIILiteral("browserName"), platformCapabilities.browserName.value());
+        matchedCapabilities->setString("browserName"_s, platformCapabilities.browserName.value());
     if (platformCapabilities.browserVersion)
-        matchedCapabilities->setString(ASCIILiteral("browserVersion"), platformCapabilities.browserVersion.value());
+        matchedCapabilities->setString("browserVersion"_s, platformCapabilities.browserVersion.value());
     if (platformCapabilities.platformName)
-        matchedCapabilities->setString(ASCIILiteral("platformName"), platformCapabilities.platformName.value());
+        matchedCapabilities->setString("platformName"_s, platformCapabilities.platformName.value());
     if (platformCapabilities.acceptInsecureCerts)
-        matchedCapabilities->setBoolean(ASCIILiteral("acceptInsecureCerts"), platformCapabilities.acceptInsecureCerts.value());
+        matchedCapabilities->setBoolean("acceptInsecureCerts"_s, platformCapabilities.acceptInsecureCerts.value());
     if (platformCapabilities.setWindowRect)
-        matchedCapabilities->setBoolean(ASCIILiteral("setWindowRect"), platformCapabilities.setWindowRect.value());
+        matchedCapabilities->setBoolean("setWindowRect"_s, platformCapabilities.setWindowRect.value());
 
     auto end = mergedCapabilities.end();
     for (auto it = mergedCapabilities.begin(); it != end; ++it) {
@@ -526,7 +538,7 @@ Vector<Capabilities> WebDriverService::processCapabilities(const JSON::Object& p
 
     // 1. Let capabilities request be the result of getting the property "capabilities" from parameters.
     RefPtr<JSON::Object> capabilitiesObject;
-    if (!parameters.getObject(ASCIILiteral("capabilities"), capabilitiesObject)) {
+    if (!parameters.getObject("capabilities"_s, capabilitiesObject)) {
         completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument));
         return { };
     }
@@ -534,7 +546,7 @@ Vector<Capabilities> WebDriverService::processCapabilities(const JSON::Object& p
     // 2. Let required capabilities be the result of getting the property "alwaysMatch" from capabilities request.
     RefPtr<JSON::Value> requiredCapabilitiesValue;
     RefPtr<JSON::Object> requiredCapabilities;
-    if (!capabilitiesObject->getValue(ASCIILiteral("alwaysMatch"), requiredCapabilitiesValue))
+    if (!capabilitiesObject->getValue("alwaysMatch"_s, requiredCapabilitiesValue))
         // 2.1. If required capabilities is undefined, set the value to an empty JSON Object.
         requiredCapabilities = JSON::Object::create();
     else if (!requiredCapabilitiesValue->asObject(requiredCapabilities)) {
@@ -552,7 +564,7 @@ Vector<Capabilities> WebDriverService::processCapabilities(const JSON::Object& p
     // 3. Let all first match capabilities be the result of getting the property "firstMatch" from capabilities request.
     RefPtr<JSON::Value> firstMatchCapabilitiesValue;
     RefPtr<JSON::Array> firstMatchCapabilitiesList;
-    if (!capabilitiesObject->getValue(ASCIILiteral("firstMatch"), firstMatchCapabilitiesValue)) {
+    if (!capabilitiesObject->getValue("firstMatch"_s, firstMatchCapabilitiesValue)) {
         // 3.1. If all first match capabilities is undefined, set the value to a JSON List with a single entry of an empty JSON Object.
         firstMatchCapabilitiesList = JSON::Array::create();
         firstMatchCapabilitiesList->pushObject(JSON::Object::create());
@@ -647,7 +659,7 @@ void WebDriverService::connectToBrowser(Vector<Capabilities>&& capabilitiesList,
 
     auto sessionHost = std::make_unique<SessionHost>(capabilitiesList.takeLast());
     auto* sessionHostPtr = sessionHost.get();
-    sessionHostPtr->connectToBrowser([this, capabilitiesList = WTFMove(capabilitiesList), sessionHost = WTFMove(sessionHost), completionHandler = WTFMove(completionHandler)](std::optional<String> error) mutable {
+    sessionHostPtr->connectToBrowser([this, capabilitiesList = WTFMove(capabilitiesList), sessionHost = WTFMove(sessionHost), completionHandler = WTFMove(completionHandler)](Optional<String> error) mutable {
         if (error) {
             completionHandler(CommandResult::fail(CommandResult::ErrorCode::SessionNotCreated, makeString("Failed to connect to browser: ", error.value())));
             return;
@@ -660,7 +672,7 @@ void WebDriverService::connectToBrowser(Vector<Capabilities>&& capabilitiesList,
 void WebDriverService::createSession(Vector<Capabilities>&& capabilitiesList, std::unique_ptr<SessionHost>&& sessionHost, Function<void (CommandResult&&)>&& completionHandler)
 {
     auto* sessionHostPtr = sessionHost.get();
-    sessionHostPtr->startAutomationSession([this, capabilitiesList = WTFMove(capabilitiesList), sessionHost = WTFMove(sessionHost), completionHandler = WTFMove(completionHandler)](bool capabilitiesDidMatch, std::optional<String> errorMessage) mutable {
+    sessionHostPtr->startAutomationSession([this, capabilitiesList = WTFMove(capabilitiesList), sessionHost = WTFMove(sessionHost), completionHandler = WTFMove(completionHandler)](bool capabilitiesDidMatch, Optional<String> errorMessage) mutable {
         if (errorMessage) {
             completionHandler(CommandResult::fail(CommandResult::ErrorCode::UnknownError, errorMessage.value()));
             return;
@@ -680,58 +692,51 @@ void WebDriverService::createSession(Vector<Capabilities>&& capabilitiesList, st
             m_session = WTFMove(session);
 
             RefPtr<JSON::Object> resultObject = JSON::Object::create();
-            resultObject->setString(ASCIILiteral("sessionId"), m_session->id());
+            resultObject->setString("sessionId"_s, m_session->id());
             RefPtr<JSON::Object> capabilitiesObject = JSON::Object::create();
             const auto& capabilities = m_session->capabilities();
-            if (capabilities.browserName)
-                capabilitiesObject->setString(ASCIILiteral("browserName"), capabilities.browserName.value());
-            if (capabilities.browserVersion)
-                capabilitiesObject->setString(ASCIILiteral("browserVersion"), capabilities.browserVersion.value());
-            if (capabilities.platformName)
-                capabilitiesObject->setString(ASCIILiteral("platformName"), capabilities.platformName.value());
-            if (capabilities.acceptInsecureCerts)
-                capabilitiesObject->setBoolean(ASCIILiteral("acceptInsecureCerts"), capabilities.acceptInsecureCerts.value());
-            if (capabilities.setWindowRect)
-                capabilitiesObject->setBoolean(ASCIILiteral("setWindowRect"), capabilities.setWindowRect.value());
-            if (capabilities.unhandledPromptBehavior) {
-                switch (capabilities.unhandledPromptBehavior.value()) {
-                case UnhandledPromptBehavior::Dismiss:
-                    capabilitiesObject->setString(ASCIILiteral("unhandledPromptBehavior"), "dismiss");
-                    break;
-                case UnhandledPromptBehavior::Accept:
-                    capabilitiesObject->setString(ASCIILiteral("unhandledPromptBehavior"), "accept");
-                    break;
-                case UnhandledPromptBehavior::DismissAndNotify:
-                    capabilitiesObject->setString(ASCIILiteral("unhandledPromptBehavior"), "dismiss and notify");
-                    break;
-                case UnhandledPromptBehavior::AcceptAndNotify:
-                    capabilitiesObject->setString(ASCIILiteral("unhandledPromptBehavior"), "accept and notify");
-                    break;
-                case UnhandledPromptBehavior::Ignore:
-                    capabilitiesObject->setString(ASCIILiteral("unhandledPromptBehavior"), "ignore");
-                    break;
-                }
+            capabilitiesObject->setString("browserName"_s, capabilities.browserName.valueOr(emptyString()));
+            capabilitiesObject->setString("browserVersion"_s, capabilities.browserVersion.valueOr(emptyString()));
+            capabilitiesObject->setString("platformName"_s, capabilities.platformName.valueOr(emptyString()));
+            capabilitiesObject->setBoolean("acceptInsecureCerts"_s, capabilities.acceptInsecureCerts.valueOr(false));
+            capabilitiesObject->setBoolean("setWindowRect"_s, capabilities.setWindowRect.valueOr(true));
+            switch (capabilities.unhandledPromptBehavior.valueOr(UnhandledPromptBehavior::DismissAndNotify)) {
+            case UnhandledPromptBehavior::Dismiss:
+                capabilitiesObject->setString("unhandledPromptBehavior"_s, "dismiss");
+                break;
+            case UnhandledPromptBehavior::Accept:
+                capabilitiesObject->setString("unhandledPromptBehavior"_s, "accept");
+                break;
+            case UnhandledPromptBehavior::DismissAndNotify:
+                capabilitiesObject->setString("unhandledPromptBehavior"_s, "dismiss and notify");
+                break;
+            case UnhandledPromptBehavior::AcceptAndNotify:
+                capabilitiesObject->setString("unhandledPromptBehavior"_s, "accept and notify");
+                break;
+            case UnhandledPromptBehavior::Ignore:
+                capabilitiesObject->setString("unhandledPromptBehavior"_s, "ignore");
+                break;
             }
-            switch (capabilities.pageLoadStrategy.value_or(PageLoadStrategy::Normal)) {
+            switch (capabilities.pageLoadStrategy.valueOr(PageLoadStrategy::Normal)) {
             case PageLoadStrategy::None:
-                capabilitiesObject->setString(ASCIILiteral("pageLoadStrategy"), "none");
+                capabilitiesObject->setString("pageLoadStrategy"_s, "none");
                 break;
             case PageLoadStrategy::Normal:
-                capabilitiesObject->setString(ASCIILiteral("pageLoadStrategy"), "normal");
+                capabilitiesObject->setString("pageLoadStrategy"_s, "normal");
                 break;
             case PageLoadStrategy::Eager:
-                capabilitiesObject->setString(ASCIILiteral("pageLoadStrategy"), "eager");
+                capabilitiesObject->setString("pageLoadStrategy"_s, "eager");
                 break;
             }
             // FIXME: implement proxy support.
-            capabilitiesObject->setObject(ASCIILiteral("proxy"), JSON::Object::create());
+            capabilitiesObject->setObject("proxy"_s, JSON::Object::create());
             RefPtr<JSON::Object> timeoutsObject = JSON::Object::create();
-            timeoutsObject->setInteger(ASCIILiteral("script"), m_session->scriptTimeout().millisecondsAs<int>());
-            timeoutsObject->setInteger(ASCIILiteral("pageLoad"), m_session->pageLoadTimeout().millisecondsAs<int>());
-            timeoutsObject->setInteger(ASCIILiteral("implicit"), m_session->implicitWaitTimeout().millisecondsAs<int>());
-            capabilitiesObject->setObject(ASCIILiteral("timeouts"), WTFMove(timeoutsObject));
+            timeoutsObject->setInteger("script"_s, m_session->scriptTimeout().millisecondsAs<int>());
+            timeoutsObject->setInteger("pageLoad"_s, m_session->pageLoadTimeout().millisecondsAs<int>());
+            timeoutsObject->setInteger("implicit"_s, m_session->implicitWaitTimeout().millisecondsAs<int>());
+            capabilitiesObject->setObject("timeouts"_s, WTFMove(timeoutsObject));
 
-            resultObject->setObject(ASCIILiteral("capabilities"), WTFMove(capabilitiesObject));
+            resultObject->setObject("capabilities"_s, WTFMove(capabilitiesObject));
             completionHandler(CommandResult::success(WTFMove(resultObject)));
         });
     });
@@ -742,7 +747,7 @@ void WebDriverService::deleteSession(RefPtr<JSON::Object>&& parameters, Function
     // §8.2 Delete Session.
     // https://www.w3.org/TR/webdriver/#delete-session
     String sessionID;
-    if (!parameters->getString(ASCIILiteral("sessionId"), sessionID)) {
+    if (!parameters->getString("sessionId"_s, sessionID)) {
         completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument));
         return;
     }
@@ -753,8 +758,12 @@ void WebDriverService::deleteSession(RefPtr<JSON::Object>&& parameters, Function
     }
 
     auto session = std::exchange(m_session, nullptr);
-    session->close([this, session, completionHandler = WTFMove(completionHandler)](CommandResult&& result) mutable {
-        completionHandler(WTFMove(result));
+    session->close([session, completionHandler = WTFMove(completionHandler)](CommandResult&& result) mutable {
+        // Ignore unknown errors when closing the session if the browser is closed.
+        if (result.isError() && result.errorCode() == CommandResult::ErrorCode::UnknownError && !session->isConnected())
+            completionHandler(CommandResult::success());
+        else
+            completionHandler(WTFMove(result));
     });
 }
 
@@ -763,8 +772,8 @@ void WebDriverService::status(RefPtr<JSON::Object>&&, Function<void (CommandResu
     // §8.3 Status
     // https://w3c.github.io/webdriver/webdriver-spec.html#status
     auto body = JSON::Object::create();
-    body->setBoolean(ASCIILiteral("ready"), !m_session);
-    body->setString(ASCIILiteral("message"), m_session ? ASCIILiteral("A session already exists") : ASCIILiteral("No sessions"));
+    body->setBoolean("ready"_s, !m_session);
+    body->setString("message"_s, m_session ? "A session already exists"_s : "No sessions"_s);
     completionHandler(CommandResult::success(WTFMove(body)));
 }
 
@@ -802,7 +811,7 @@ void WebDriverService::go(RefPtr<JSON::Object>&& parameters, Function<void (Comm
         return;
 
     String url;
-    if (!parameters->getString(ASCIILiteral("url"), url)) {
+    if (!parameters->getString("url"_s, url)) {
         completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument));
         return;
     }
@@ -917,8 +926,8 @@ void WebDriverService::setWindowRect(RefPtr<JSON::Object>&& parameters, Function
     // §10.7.2 Set Window Rect.
     // https://w3c.github.io/webdriver/webdriver-spec.html#set-window-rect
     RefPtr<JSON::Value> value;
-    std::optional<double> width;
-    if (parameters->getValue(ASCIILiteral("width"), value)) {
+    Optional<double> width;
+    if (parameters->getValue("width"_s, value)) {
         if (auto number = valueAsNumberInRange(*value))
             width = number;
         else if (!value->isNull()) {
@@ -926,8 +935,8 @@ void WebDriverService::setWindowRect(RefPtr<JSON::Object>&& parameters, Function
             return;
         }
     }
-    std::optional<double> height;
-    if (parameters->getValue(ASCIILiteral("height"), value)) {
+    Optional<double> height;
+    if (parameters->getValue("height"_s, value)) {
         if (auto number = valueAsNumberInRange(*value))
             height = number;
         else if (!value->isNull()) {
@@ -935,8 +944,8 @@ void WebDriverService::setWindowRect(RefPtr<JSON::Object>&& parameters, Function
             return;
         }
     }
-    std::optional<double> x;
-    if (parameters->getValue(ASCIILiteral("x"), value)) {
+    Optional<double> x;
+    if (parameters->getValue("x"_s, value)) {
         if (auto number = valueAsNumberInRange(*value, INT_MIN))
             x = number;
         else if (!value->isNull()) {
@@ -944,8 +953,8 @@ void WebDriverService::setWindowRect(RefPtr<JSON::Object>&& parameters, Function
             return;
         }
     }
-    std::optional<double> y;
-    if (parameters->getValue(ASCIILiteral("y"), value)) {
+    Optional<double> y;
+    if (parameters->getValue("y"_s, value)) {
         if (auto number = valueAsNumberInRange(*value, INT_MIN))
             y = number;
         else if (!value->isNull()) {
@@ -961,6 +970,30 @@ void WebDriverService::setWindowRect(RefPtr<JSON::Object>&& parameters, Function
         m_session->setWindowRect(x, y, width, height, WTFMove(completionHandler));
 }
 
+void WebDriverService::maximizeWindow(RefPtr<JSON::Object>&& parameters, Function<void (CommandResult&&)>&& completionHandler)
+{
+    // §10.7.3 Maximize Window
+    // https://w3c.github.io/webdriver/#maximize-window
+    if (findSessionOrCompleteWithError(*parameters, completionHandler))
+        m_session->maximizeWindow(WTFMove(completionHandler));
+}
+
+void WebDriverService::minimizeWindow(RefPtr<JSON::Object>&& parameters, Function<void (CommandResult&&)>&& completionHandler)
+{
+    // §10.7.4 Minimize Window
+    // https://w3c.github.io/webdriver/#minimize-window
+    if (findSessionOrCompleteWithError(*parameters, completionHandler))
+        m_session->minimizeWindow(WTFMove(completionHandler));
+}
+
+void WebDriverService::fullscreenWindow(RefPtr<JSON::Object>&& parameters, Function<void (CommandResult&&)>&& completionHandler)
+{
+    // §10.7.5 Fullscreen Window
+    // https://w3c.github.io/webdriver/#fullscreen-window
+    if (findSessionOrCompleteWithError(*parameters, completionHandler))
+        m_session->fullscreenWindow(WTFMove(completionHandler));
+}
+
 void WebDriverService::closeWindow(RefPtr<JSON::Object>&& parameters, Function<void (CommandResult&&)>&& completionHandler)
 {
     // §10.2 Close Window.
@@ -990,7 +1023,7 @@ void WebDriverService::switchToWindow(RefPtr<JSON::Object>&& parameters, Functio
         return;
 
     String handle;
-    if (!parameters->getString(ASCIILiteral("handle"), handle)) {
+    if (!parameters->getString("handle"_s, handle)) {
         completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument));
         return;
     }
@@ -1014,7 +1047,7 @@ void WebDriverService::switchToFrame(RefPtr<JSON::Object>&& parameters, Function
         return;
 
     RefPtr<JSON::Value> frameID;
-    if (!parameters->getValue(ASCIILiteral("id"), frameID)) {
+    if (!parameters->getValue("id"_s, frameID)) {
         completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument));
         return;
     }
@@ -1044,12 +1077,12 @@ void WebDriverService::switchToParentFrame(RefPtr<JSON::Object>&& parameters, Fu
     });
 }
 
-static std::optional<String> findElementOrCompleteWithError(JSON::Object& parameters, Function<void (CommandResult&&)>& completionHandler)
+static Optional<String> findElementOrCompleteWithError(JSON::Object& parameters, Function<void (CommandResult&&)>& completionHandler)
 {
     String elementID;
-    if (!parameters.getString(ASCIILiteral("elementId"), elementID) || elementID.isEmpty()) {
+    if (!parameters.getString("elementId"_s, elementID) || elementID.isEmpty()) {
         completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument));
-        return std::nullopt;
+        return WTF::nullopt;
     }
     return elementID;
 }
@@ -1067,11 +1100,11 @@ static inline bool isValidStrategy(const String& strategy)
 
 static bool findStrategyAndSelectorOrCompleteWithError(JSON::Object& parameters, Function<void (CommandResult&&)>& completionHandler, String& strategy, String& selector)
 {
-    if (!parameters.getString(ASCIILiteral("using"), strategy) || !isValidStrategy(strategy)) {
+    if (!parameters.getString("using"_s, strategy) || !isValidStrategy(strategy)) {
         completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument));
         return false;
     }
-    if (!parameters.getString(ASCIILiteral("value"), selector)) {
+    if (!parameters.getString("value"_s, selector)) {
         completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument));
         return false;
     }
@@ -1196,7 +1229,7 @@ void WebDriverService::getElementAttribute(RefPtr<JSON::Object>&& parameters, Fu
         return;
 
     String attribute;
-    if (!parameters->getString(ASCIILiteral("name"), attribute)) {
+    if (!parameters->getString("name"_s, attribute)) {
         completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument));
         return;
     }
@@ -1216,7 +1249,7 @@ void WebDriverService::getElementProperty(RefPtr<JSON::Object>&& parameters, Fun
         return;
 
     String attribute;
-    if (!parameters->getString(ASCIILiteral("name"), attribute)) {
+    if (!parameters->getString("name"_s, attribute)) {
         completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument));
         return;
     }
@@ -1236,7 +1269,7 @@ void WebDriverService::getElementCSSValue(RefPtr<JSON::Object>&& parameters, Fun
         return;
 
     String cssProperty;
-    if (!parameters->getString(ASCIILiteral("name"), cssProperty)) {
+    if (!parameters->getString("name"_s, cssProperty)) {
         completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument));
         return;
     }
@@ -1353,41 +1386,22 @@ void WebDriverService::elementSendKeys(RefPtr<JSON::Object>&& parameters, Functi
     if (!elementID)
         return;
 
-    RefPtr<JSON::Array> valueArray;
-    if (!parameters->getArray(ASCIILiteral("value"), valueArray)) {
-        completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument));
-        return;
-    }
-
-    unsigned valueArrayLength = valueArray->length();
-    if (!valueArrayLength) {
-        completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument));
-        return;
-    }
-    Vector<String> value;
-    value.reserveInitialCapacity(valueArrayLength);
-    for (unsigned i = 0; i < valueArrayLength; ++i) {
-        if (auto keyValue = valueArray->get(i)) {
-            String key;
-            if (keyValue->asString(key))
-                value.uncheckedAppend(WTFMove(key));
-        }
-    }
-    if (!value.size()) {
+    String text;
+    if (!parameters->getString("text"_s, text) || text.isEmpty()) {
         completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument));
         return;
     }
 
-    m_session->elementSendKeys(elementID.value(), WTFMove(value), WTFMove(completionHandler));
+    m_session->elementSendKeys(elementID.value(), text, WTFMove(completionHandler));
 }
 
 static bool findScriptAndArgumentsOrCompleteWithError(JSON::Object& parameters, Function<void (CommandResult&&)>& completionHandler, String& script, RefPtr<JSON::Array>& arguments)
 {
-    if (!parameters.getString(ASCIILiteral("script"), script)) {
+    if (!parameters.getString("script"_s, script)) {
         completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument));
         return false;
     }
-    if (!parameters.getArray(ASCIILiteral("args"), arguments)) {
+    if (!parameters.getArray("args"_s, arguments)) {
         completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument));
         return false;
     }
@@ -1460,7 +1474,7 @@ void WebDriverService::getNamedCookie(RefPtr<JSON::Object>&& parameters, Functio
         return;
 
     String name;
-    if (!parameters->getString(ASCIILiteral("name"), name)) {
+    if (!parameters->getString("name"_s, name)) {
         completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument));
         return;
     }
@@ -1474,43 +1488,43 @@ void WebDriverService::getNamedCookie(RefPtr<JSON::Object>&& parameters, Functio
     });
 }
 
-static std::optional<Session::Cookie> deserializeCookie(JSON::Object& cookieObject)
+static Optional<Session::Cookie> deserializeCookie(JSON::Object& cookieObject)
 {
     Session::Cookie cookie;
-    if (!cookieObject.getString(ASCIILiteral("name"), cookie.name) || cookie.name.isEmpty())
-        return std::nullopt;
-    if (!cookieObject.getString(ASCIILiteral("value"), cookie.value) || cookie.value.isEmpty())
-        return std::nullopt;
+    if (!cookieObject.getString("name"_s, cookie.name) || cookie.name.isEmpty())
+        return WTF::nullopt;
+    if (!cookieObject.getString("value"_s, cookie.value) || cookie.value.isEmpty())
+        return WTF::nullopt;
 
     RefPtr<JSON::Value> value;
-    if (cookieObject.getValue(ASCIILiteral("path"), value)) {
+    if (cookieObject.getValue("path"_s, value)) {
         String path;
         if (!value->asString(path))
-            return std::nullopt;
+            return WTF::nullopt;
         cookie.path = path;
     }
-    if (cookieObject.getValue(ASCIILiteral("domain"), value)) {
+    if (cookieObject.getValue("domain"_s, value)) {
         String domain;
         if (!value->asString(domain))
-            return std::nullopt;
+            return WTF::nullopt;
         cookie.domain = domain;
     }
-    if (cookieObject.getValue(ASCIILiteral("secure"), value)) {
+    if (cookieObject.getValue("secure"_s, value)) {
         bool secure;
         if (!value->asBoolean(secure))
-            return std::nullopt;
+            return WTF::nullopt;
         cookie.secure = secure;
     }
-    if (cookieObject.getValue(ASCIILiteral("httpOnly"), value)) {
+    if (cookieObject.getValue("httpOnly"_s, value)) {
         bool httpOnly;
         if (!value->asBoolean(httpOnly))
-            return std::nullopt;
+            return WTF::nullopt;
         cookie.httpOnly = httpOnly;
     }
-    if (cookieObject.getValue(ASCIILiteral("expiry"), value)) {
+    if (cookieObject.getValue("expiry"_s, value)) {
         auto expiry = unsignedValue(*value);
         if (!expiry)
-            return std::nullopt;
+            return WTF::nullopt;
         cookie.expiry = expiry.value();
     }
 
@@ -1525,7 +1539,7 @@ void WebDriverService::addCookie(RefPtr<JSON::Object>&& parameters, Function<voi
         return;
 
     RefPtr<JSON::Object> cookieObject;
-    if (!parameters->getObject(ASCIILiteral("cookie"), cookieObject)) {
+    if (!parameters->getObject("cookie"_s, cookieObject)) {
         completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument));
         return;
     }
@@ -1553,7 +1567,7 @@ void WebDriverService::deleteCookie(RefPtr<JSON::Object>&& parameters, Function<
         return;
 
     String name;
-    if (!parameters->getString(ASCIILiteral("name"), name)) {
+    if (!parameters->getString("name"_s, name)) {
         completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument));
         return;
     }
@@ -1583,6 +1597,371 @@ void WebDriverService::deleteAllCookies(RefPtr<JSON::Object>&& parameters, Funct
     });
 }
 
+static bool processPauseAction(JSON::Object& actionItem, Action& action, Optional<String>& errorMessage)
+{
+    RefPtr<JSON::Value> durationValue;
+    if (!actionItem.getValue("duration"_s, durationValue)) {
+        errorMessage = String("The parameter 'duration' is missing in pause action");
+        return false;
+    }
+
+    auto duration = unsignedValue(*durationValue);
+    if (!duration) {
+        errorMessage = String("The parameter 'duration' is invalid in pause action");
+        return false;
+    }
+
+    action.duration = duration.value();
+    return true;
+}
+
+static Optional<Action> processNullAction(const String& id, JSON::Object& actionItem, Optional<String>& errorMessage)
+{
+    String subtype;
+    actionItem.getString("type"_s, subtype);
+    if (subtype != "pause") {
+        errorMessage = String("The parameter 'type' in null action is invalid or missing");
+        return WTF::nullopt;
+    }
+
+    Action action(id, Action::Type::None, Action::Subtype::Pause);
+    if (!processPauseAction(actionItem, action, errorMessage))
+        return WTF::nullopt;
+
+    return action;
+}
+
+static Optional<Action> processKeyAction(const String& id, JSON::Object& actionItem, Optional<String>& errorMessage)
+{
+    Action::Subtype actionSubtype;
+    String subtype;
+    actionItem.getString("type"_s, subtype);
+    if (subtype == "pause")
+        actionSubtype = Action::Subtype::Pause;
+    else if (subtype == "keyUp")
+        actionSubtype = Action::Subtype::KeyUp;
+    else if (subtype == "keyDown")
+        actionSubtype = Action::Subtype::KeyDown;
+    else {
+        errorMessage = String("The parameter 'type' of key action is invalid");
+        return WTF::nullopt;
+    }
+
+    Action action(id, Action::Type::Key, actionSubtype);
+
+    switch (actionSubtype) {
+    case Action::Subtype::Pause:
+        if (!processPauseAction(actionItem, action, errorMessage))
+            return WTF::nullopt;
+        break;
+    case Action::Subtype::KeyUp:
+    case Action::Subtype::KeyDown: {
+        RefPtr<JSON::Value> keyValue;
+        if (!actionItem.getValue("value"_s, keyValue)) {
+            errorMessage = String("The paramater 'value' is missing for key up/down action");
+            return WTF::nullopt;
+        }
+        String key;
+        if (!keyValue->asString(key) || key.isEmpty()) {
+            errorMessage = String("The paramater 'value' is invalid for key up/down action");
+            return WTF::nullopt;
+        }
+        // FIXME: check single unicode code point.
+        action.key = key;
+        break;
+    }
+    case Action::Subtype::PointerUp:
+    case Action::Subtype::PointerDown:
+    case Action::Subtype::PointerMove:
+    case Action::Subtype::PointerCancel:
+        ASSERT_NOT_REACHED();
+    }
+
+    return action;
+}
+
+static MouseButton actionMouseButton(unsigned button)
+{
+    // MouseEvent.button
+    // https://www.w3.org/TR/uievents/#ref-for-dom-mouseevent-button-1
+    switch (button) {
+    case 0:
+        return MouseButton::Left;
+    case 1:
+        return MouseButton::Middle;
+    case 2:
+        return MouseButton::Right;
+    }
+
+    return MouseButton::None;
+}
+
+static Optional<Action> processPointerAction(const String& id, PointerParameters& parameters, JSON::Object& actionItem, Optional<String>& errorMessage)
+{
+    Action::Subtype actionSubtype;
+    String subtype;
+    actionItem.getString("type"_s, subtype);
+    if (subtype == "pause")
+        actionSubtype = Action::Subtype::Pause;
+    else if (subtype == "pointerUp")
+        actionSubtype = Action::Subtype::PointerUp;
+    else if (subtype == "pointerDown")
+        actionSubtype = Action::Subtype::PointerDown;
+    else if (subtype == "pointerMove")
+        actionSubtype = Action::Subtype::PointerMove;
+    else if (subtype == "pointerCancel")
+        actionSubtype = Action::Subtype::PointerCancel;
+    else {
+        errorMessage = String("The parameter 'type' of pointer action is invalid");
+        return WTF::nullopt;
+    }
+
+    Action action(id, Action::Type::Pointer, actionSubtype);
+    action.pointerType = parameters.pointerType;
+
+    switch (actionSubtype) {
+    case Action::Subtype::Pause:
+        if (!processPauseAction(actionItem, action, errorMessage))
+            return WTF::nullopt;
+        break;
+    case Action::Subtype::PointerUp:
+    case Action::Subtype::PointerDown: {
+        RefPtr<JSON::Value> buttonValue;
+        if (!actionItem.getValue("button"_s, buttonValue)) {
+            errorMessage = String("The paramater 'button' is missing for pointer up/down action");
+            return WTF::nullopt;
+        }
+        auto button = unsignedValue(*buttonValue);
+        if (!button) {
+            errorMessage = String("The paramater 'button' is invalid for pointer up/down action");
+            return WTF::nullopt;
+        }
+        action.button = actionMouseButton(button.value());
+        break;
+    }
+    case Action::Subtype::PointerMove: {
+        RefPtr<JSON::Value> durationValue;
+        if (actionItem.getValue("duration"_s, durationValue)) {
+            auto duration = unsignedValue(*durationValue);
+            if (!duration) {
+                errorMessage = String("The parameter 'duration' is invalid in pointer move action");
+                return WTF::nullopt;
+            }
+            action.duration = duration.value();
+        }
+
+        RefPtr<JSON::Value> originValue;
+        if (actionItem.getValue("origin"_s, originValue)) {
+            if (originValue->type() == JSON::Value::Type::Object) {
+                RefPtr<JSON::Object> originObject;
+                originValue->asObject(originObject);
+                String elementID;
+                if (!originObject->getString(Session::webElementIdentifier(), elementID)) {
+                    errorMessage = String("The parameter 'origin' is not a valid web element object in pointer move action");
+                    return WTF::nullopt;
+                }
+                action.origin = PointerOrigin { PointerOrigin::Type::Element, elementID };
+            } else {
+                String origin;
+                originValue->asString(origin);
+                if (origin == "viewport")
+                    action.origin = PointerOrigin { PointerOrigin::Type::Viewport, WTF::nullopt };
+                else if (origin == "pointer")
+                    action.origin = PointerOrigin { PointerOrigin::Type::Pointer, WTF::nullopt };
+                else {
+                    errorMessage = String("The parameter 'origin' is invalid in pointer move action");
+                    return WTF::nullopt;
+                }
+            }
+        } else
+            action.origin = PointerOrigin { PointerOrigin::Type::Viewport, WTF::nullopt };
+
+        RefPtr<JSON::Value> xValue;
+        if (actionItem.getValue("x"_s, xValue)) {
+            auto x = valueAsNumberInRange(*xValue, INT_MIN);
+            if (!x) {
+                errorMessage = String("The paramater 'x' is invalid for pointer move action");
+                return WTF::nullopt;
+            }
+            action.x = x.value();
+        }
+
+        RefPtr<JSON::Value> yValue;
+        if (actionItem.getValue("y"_s, yValue)) {
+            auto y = valueAsNumberInRange(*yValue, INT_MIN);
+            if (!y) {
+                errorMessage = String("The paramater 'y' is invalid for pointer move action");
+                return WTF::nullopt;
+            }
+            action.y = y.value();
+        }
+        break;
+    }
+    case Action::Subtype::PointerCancel:
+        break;
+    case Action::Subtype::KeyUp:
+    case Action::Subtype::KeyDown:
+        ASSERT_NOT_REACHED();
+    }
+
+    return action;
+}
+
+static Optional<PointerParameters> processPointerParameters(JSON::Object& actionSequence, Optional<String>& errorMessage)
+{
+    PointerParameters parameters;
+    RefPtr<JSON::Value> parametersDataValue;
+    if (!actionSequence.getValue("parameters"_s, parametersDataValue))
+        return parameters;
+
+    RefPtr<JSON::Object> parametersData;
+    if (!parametersDataValue->asObject(parametersData)) {
+        errorMessage = String("Action sequence pointer parameters is not an object");
+        return WTF::nullopt;
+    }
+
+    String pointerType;
+    if (!parametersData->getString("pointerType"_s, pointerType))
+        return parameters;
+
+    if (pointerType == "mouse")
+        parameters.pointerType = PointerType::Mouse;
+    else if (pointerType == "pen")
+        parameters.pointerType = PointerType::Pen;
+    else if (pointerType == "touch")
+        parameters.pointerType = PointerType::Touch;
+    else {
+        errorMessage = String("The parameter 'pointerType' in action sequence pointer parameters is invalid");
+        return WTF::nullopt;
+    }
+
+    return parameters;
+}
+
+static Optional<Vector<Action>> processInputActionSequence(Session& session, JSON::Value& actionSequenceValue, Optional<String>& errorMessage)
+{
+    RefPtr<JSON::Object> actionSequence;
+    if (!actionSequenceValue.asObject(actionSequence)) {
+        errorMessage = String("The action sequence is not an object");
+        return WTF::nullopt;
+    }
+
+    String type;
+    actionSequence->getString("type"_s, type);
+    InputSource::Type inputSourceType;
+    if (type == "key")
+        inputSourceType = InputSource::Type::Key;
+    else if (type == "pointer")
+        inputSourceType = InputSource::Type::Pointer;
+    else if (type == "none")
+        inputSourceType = InputSource::Type::None;
+    else {
+        errorMessage = String("The parameter 'type' is invalid or missing in action sequence");
+        return WTF::nullopt;
+    }
+
+    String id;
+    if (!actionSequence->getString("id"_s, id)) {
+        errorMessage = String("The parameter 'id' is invalid or missing in action sequence");
+        return WTF::nullopt;
+    }
+
+    Optional<PointerParameters> parameters;
+    Optional<PointerType> pointerType;
+    if (inputSourceType == InputSource::Type::Pointer) {
+        parameters = processPointerParameters(*actionSequence, errorMessage);
+        if (!parameters)
+            return WTF::nullopt;
+
+        pointerType = parameters->pointerType;
+    }
+
+    auto& inputSource = session.getOrCreateInputSource(id, inputSourceType, pointerType);
+    if (inputSource.type != inputSourceType) {
+        errorMessage = String("Action sequence type doesn't match input source type");
+        return WTF::nullopt;
+    }
+
+    if (inputSource.type ==  InputSource::Type::Pointer && inputSource.pointerType != pointerType) {
+        errorMessage = String("Action sequence pointer type doesn't match input source pointer type");
+        return WTF::nullopt;
+    }
+
+    RefPtr<JSON::Array> actionItems;
+    if (!actionSequence->getArray("actions"_s, actionItems)) {
+        errorMessage = String("The parameter 'actions' is invalid or not present in action sequence");
+        return WTF::nullopt;
+    }
+
+    Vector<Action> actions;
+    unsigned actionItemsLength = actionItems->length();
+    for (unsigned i = 0; i < actionItemsLength; ++i) {
+        auto actionItemValue = actionItems->get(i);
+        RefPtr<JSON::Object> actionItem;
+        if (!actionItemValue->asObject(actionItem)) {
+            errorMessage = String("An action in action sequence is not an object");
+            return WTF::nullopt;
+        }
+
+        Optional<Action> action;
+        if (inputSourceType == InputSource::Type::None)
+            action = processNullAction(id, *actionItem, errorMessage);
+        else if (inputSourceType == InputSource::Type::Key)
+            action = processKeyAction(id, *actionItem, errorMessage);
+        else if (inputSourceType == InputSource::Type::Pointer)
+            action = processPointerAction(id, parameters.value(), *actionItem, errorMessage);
+        if (!action)
+            return WTF::nullopt;
+
+        actions.append(action.value());
+    }
+
+    return actions;
+}
+
+void WebDriverService::performActions(RefPtr<JSON::Object>&& parameters, Function<void (CommandResult&&)>&& completionHandler)
+{
+    // §17.5 Perform Actions.
+    // https://w3c.github.io/webdriver/webdriver-spec.html#perform-actions
+    if (!findSessionOrCompleteWithError(*parameters, completionHandler))
+        return;
+
+    RefPtr<JSON::Array> actionsArray;
+    if (!parameters->getArray("actions"_s, actionsArray)) {
+        completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument, String("The paramater 'actions' is invalid or not present")));
+        return;
+    }
+
+    Optional<String> errorMessage;
+    Vector<Vector<Action>> actionsByTick;
+    unsigned actionsArrayLength = actionsArray->length();
+    for (unsigned i = 0; i < actionsArrayLength; ++i) {
+        auto actionSequence = actionsArray->get(i);
+        auto inputSourceActions = processInputActionSequence(*m_session, *actionSequence, errorMessage);
+        if (!inputSourceActions) {
+            completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument, errorMessage.value()));
+            return;
+        }
+        for (unsigned i = 0; i < inputSourceActions->size(); ++i) {
+            if (actionsByTick.size() < i + 1)
+                actionsByTick.append({ });
+            actionsByTick[i].append(inputSourceActions.value()[i]);
+        }
+    }
+
+    m_session->performActions(WTFMove(actionsByTick), WTFMove(completionHandler));
+}
+
+void WebDriverService::releaseActions(RefPtr<JSON::Object>&& parameters, Function<void (CommandResult&&)>&& completionHandler)
+{
+    // §17.5 Release Actions.
+    // https://w3c.github.io/webdriver/webdriver-spec.html#release-actions
+    if (!findSessionOrCompleteWithError(*parameters, completionHandler))
+        return;
+
+    m_session->releaseActions(WTFMove(completionHandler));
+}
+
 void WebDriverService::dismissAlert(RefPtr<JSON::Object>&& parameters, Function<void (CommandResult&&)>&& completionHandler)
 {
     // §18.1 Dismiss Alert.
@@ -1639,7 +2018,7 @@ void WebDriverService::sendAlertText(RefPtr<JSON::Object>&& parameters, Function
         return;
 
     String text;
-    if (!parameters->getString(ASCIILiteral("text"), text)) {
+    if (!parameters->getString("text"_s, text)) {
         completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument));
         return;
     }
@@ -1665,7 +2044,7 @@ void WebDriverService::takeScreenshot(RefPtr<JSON::Object>&& parameters, Functio
             completionHandler(WTFMove(result));
             return;
         }
-        m_session->takeScreenshot(std::nullopt, std::nullopt, WTFMove(completionHandler));
+        m_session->takeScreenshot(WTF::nullopt, WTF::nullopt, WTFMove(completionHandler));
     });
 }
 
@@ -1681,7 +2060,7 @@ void WebDriverService::takeElementScreenshot(RefPtr<JSON::Object>&& parameters,
         return;
 
     bool scrollIntoView = true;
-    parameters->getBoolean(ASCIILiteral("scroll"), scrollIntoView);
+    parameters->getBoolean("scroll"_s, scrollIntoView);
 
     m_session->waitForNavigationToComplete([this, elementID, scrollIntoView, completionHandler = WTFMove(completionHandler)](CommandResult&& result) mutable {
         if (result.isError()) {