ExecuteScript.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Forward.h>
  8. #include <AK/JsonValue.h>
  9. #include <LibJS/Forward.h>
  10. #include <LibJS/Heap/HeapFunction.h>
  11. #include <LibJS/Runtime/Value.h>
  12. #include <LibWeb/Forward.h>
  13. namespace Web::WebDriver {
  14. enum class ExecuteScriptResultType {
  15. PromiseResolved,
  16. PromiseRejected,
  17. Timeout,
  18. JavaScriptError,
  19. BrowsingContextDiscarded,
  20. StaleElement,
  21. };
  22. struct ExecuteScriptResult {
  23. ExecuteScriptResultType type;
  24. JS::Value value;
  25. };
  26. struct ExecuteScriptResultSerialized {
  27. ExecuteScriptResultType type;
  28. JsonValue value;
  29. };
  30. using OnScriptComplete = JS::HeapFunction<void(ExecuteScriptResultSerialized)>;
  31. void execute_script(HTML::BrowsingContext const&, ByteString body, JS::MarkedVector<JS::Value> arguments, Optional<u64> const& timeout_ms, JS::NonnullGCPtr<OnScriptComplete> on_complete);
  32. void execute_async_script(HTML::BrowsingContext const&, ByteString body, JS::MarkedVector<JS::Value> arguments, Optional<u64> const& timeout_ms, JS::NonnullGCPtr<OnScriptComplete> on_complete);
  33. }