mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-22 11:02:53 +00:00
We currently spin the platform event loop while awaiting scripts to complete. This causes WebContent to hang if another component is also spinning the event loop. The particular example that instigated this patch was the navigable's navigation loop (which spins until the fetch process is complete), triggered by a form submission to an iframe. So instead of spinning, we now return immediately from the script executors, after setting up listeners for either the script's promise to be resolved or for a timeout. The HTTP request to WebDriver must finish synchronously though, so now the WebDriver process spins its event loop until WebContent signals that the script completed. This should be ok - the WebDriver process isn't expected to be doing anything else in the meantime. Also, as a consequence of these changes, we now actually handle time outs. We were previously creating the timeout timer, but not starting it.
41 lines
1.1 KiB
C++
41 lines
1.1 KiB
C++
/*
|
|
* Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Forward.h>
|
|
#include <AK/JsonValue.h>
|
|
#include <LibJS/Forward.h>
|
|
#include <LibJS/Heap/HeapFunction.h>
|
|
#include <LibJS/Runtime/Value.h>
|
|
#include <LibWeb/Forward.h>
|
|
|
|
namespace Web::WebDriver {
|
|
|
|
enum class ExecuteScriptResultType {
|
|
PromiseResolved,
|
|
PromiseRejected,
|
|
Timeout,
|
|
JavaScriptError,
|
|
BrowsingContextDiscarded,
|
|
};
|
|
|
|
struct ExecuteScriptResult {
|
|
ExecuteScriptResultType type;
|
|
JS::Value value;
|
|
};
|
|
|
|
struct ExecuteScriptResultSerialized {
|
|
ExecuteScriptResultType type;
|
|
JsonValue value;
|
|
};
|
|
|
|
using OnScriptComplete = JS::HeapFunction<void(ExecuteScriptResultSerialized)>;
|
|
|
|
void execute_script(Page& page, ByteString body, JS::MarkedVector<JS::Value> arguments, Optional<u64> const& timeout_ms, JS::NonnullGCPtr<OnScriptComplete> on_complete);
|
|
void execute_async_script(Page& page, ByteString body, JS::MarkedVector<JS::Value> arguments, Optional<u64> const& timeout_ms, JS::NonnullGCPtr<OnScriptComplete> on_complete);
|
|
|
|
}
|