Commit Graph

106 Commits

Author SHA1 Message Date
Tim Ledbetter
79143833b6 LibWeb/WebDriver: Ensure error responses are serialized correctly 2024-05-30 13:53:24 -04:00
stelar7
a4e97c1598 WebDriver: Dont assume the pageLoad is an i64 2024-05-30 11:46:02 -04:00
stelar7
fa9c234976 WebDriver: Parse webSocketUrl capability 2024-05-30 11:46:02 -04:00
Andrew Kaster
ca806a3e18 WebDriver+WebContent: Add /session/🆔/window/consume-user-activation
This extension to the WebDriver spec is defined in the HTML spec, how
fun.
2024-05-29 21:30:15 +02:00
Timothy Flynn
086ddd481d Ladybird+LibWeb: Move User-Agent definitions to their own file
This is to avoid including any LibProtocol header in Objective-C source
files, which will cause a conflict between the Protocol namespace and a
@Protocol interface.

See Ladybird/AppKit/Application/ApplicationBridge.cpp for why this
conflict unfortunately cannot be worked around.
2024-05-26 18:29:24 +02:00
Aliaksandr Kalenik
e934132442 LibJS+LibWeb: Pass function metadata collected in parsing using a struct
By using separate struct we can avoid updating AST node and
ECMAScriptFunctionObject constructors every time there is a need to
add or remove some additional information colllected during parsing.
2024-05-23 09:53:31 +02:00
Aliaksandr Kalenik
ebb3d8025c LibJS: Get this from execution context for non-arrow functions
Allows to skip function environment allocation for non-arrow functions
if the only reason it is needed is to hold `this` binding.

The parser is changed to do following:
- If a function is an arrow function and uses `this` then all functions
  in a scope chain are marked to allocate function environment for
  `this` binding.
- If a function uses `new.target` then all functions in a scope chain
  are marked to allocate function environment.

`ordinary_call_bind_this()` is changed to put `this` value in execution
context when function environment allocation is skipped.

35% improvement in Octane/typescript.js
50% improvement in Octane/deltablue.js
19% improvement in Octane/raytrace.js
2024-05-22 18:30:13 +02:00
Aliaksandr Kalenik
4d5823a5bc LibWeb+LibJS: Skip function environment allocation if possible
If a function has the following properties:
- uses only local variables and registers
- does not use `this`
- does not use `new.target`
- does not use `super`
- does not use direct eval() calls

then it is possible to entirely skip function environment allocation
because it will never be used

This change adds gathering of information whether a function needs to
access `this` from environment and updates `prepare_for_ordinary_call()`
to skip allocation when possible.

For now, this optimisation is too aggressively blocked; e.g. if `this`
is used in a function scope, then all functions in outer scopes have to
allocate an environment. It could be improved in the future, although
this implementation already allows skipping >80% of environment
allocations on Discord, GitHub and Twitter.
2024-05-04 06:48:07 +02:00
Andreas Kling
b98a2be96b LibWeb: Ignore window-forwarded document.body.onfoo in detached DOM
Normally, assigning to e.g document.body.onload will forward to
window.onload. However, in a detached DOM tree, there is no associated
window, so we have nowhere to forward to, making this a no-op.

The bulk of this change is making Document::window() return a nullable
pointer, as documents created by DOMParser or DOMImplementation do not
have an associated window object, and so must be able to return null
from here.
2024-03-11 18:29:10 +01:00
Andrew Kaster
cb68c6eaf1 LibWeb: Set size of canvas used to take WebDriver screenshots explicitly
The default canvas size is 300x150 pixels. If the element or document
we are trying to screenshot for the WebDriver is not at least that size,
then we will create a canvas that is wider or taller than the actual
element we are painting, resulting in a bunch of transparent pixels
falling off the end.

This fixes 14 WPT css/CSS2/floats tests that we run in CI, and
presumably a ton of other reftests in the WPT test suite.
2024-02-21 10:10:44 +01:00
Andrew Kaster
deb11a669a LibWeb: Stub out WebDriver deserialize as a proxy capability AO
This prevents us from returning an 'unrecognized capability' error when
a WebDriver client sends us a proxy capability. We still don't actually
support setting or returning a non-empty proxy capability, though.

We just don't choke on the input capability request from the server.

This patch also doesn't actually validate the input proxy requests.
2024-02-12 11:43:22 -07:00
Andrew Kaster
bc9c710904 LibWeb: Hide WebDriver::match_route debug behind its own flag
When enabling WEBDRIVER_DEBUG globally, this function's debug spam
overpowers the rest of the useful logs.
2024-02-08 15:53:46 +01:00
Timothy Flynn
747fd86f26 LibWeb: Make WebDriver check if the BC's navigable has been destroyed
The spec steps to check if a browsing context is open have been updated
for navigables.
2024-02-06 08:40:27 +01:00
Andrew Kaster
9645daaf6c LibWeb: Remove RemoteBrowsingContext and AbstractBrowsingContext
With the transition to Navigables, and a working implementation of
window.open(), we no longer need this abstraction layer.
2024-02-05 08:05:48 -07:00
Andrew Kaster
3aee787539 LibWeb+WebContent: Convert WebDriver to choose a navigable AO
Also use the TraversableNavigable's window_handle instead of the
BrowsingContext's.
2024-02-05 08:05:48 -07:00
Dan Klishch
b5f1a48a7c AK+Everywhere: Remove JsonValue APIs with implicit default values 2024-01-21 15:47:53 -07:00
Dan Klishch
ccd701809f Everywhere: Add deprecated_ prefix to JsonValue::to_byte_string
`JsonValue::to_byte_string` has peculiar type-erasure semantics which is
not usually intended. Unfortunately, it also has a very stereotypical
name which does not warn about unexpected behavior. So let's prefix it
with `deprecated_` to make new code use `as_string` if it just wants to
get string value or `serialized<StringBuilder>` if it needs to do proper
serialization.
2024-01-12 17:41:34 -07:00
Shannon Booth
e2e7c4d574 Everywhere: Use to_number<T> instead of to_{int,uint,float,double}
In a bunch of cases, this actually ends up simplifying the code as
to_number will handle something such as:

```
Optional<I> opt;
if constexpr (IsSigned<I>)
    opt = view.to_int<I>();
else
    opt = view.to_uint<I>();
```

For us.

The main goal here however is to have a single generic number conversion
API between all of the String classes.
2023-12-23 20:41:07 +01:00
Ali Mohammad Pur
5e1499d104 Everywhere: Rename {Deprecated => Byte}String
This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).

This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
2023-12-17 18:25:10 +03:30
Daniel Bertalan
6f972c190b Everywhere: Work around Clang trunk bug with templated lambda + Variant
Since 2023-09-08, Clang trunk has had a bug which causes a segfault when
evaluating certain `requires` expressions inside templated lambdas.
There isn't an imminent fix on the horizon, so let's work around the
issue by specifying the type of the offending lambda arguments
explicitly.

See https://github.com/llvm/llvm-project/issues/67260
2023-11-05 13:41:13 -07:00
Andreas Kling
3ff81dcb65 LibWeb: Make Web::Namespace::Foo strings be FlyString
This required dealing with a *lot* of fallout, but it's all basically
just switching from DeprecatedFlyString to either FlyString or
Optional<FlyString> in a hundred places to accommodate the change.
2023-11-04 21:28:30 +01:00
Andreas Kling
f052823f5f LibWeb: Use FlyString for create_element() namespace strings 2023-11-04 21:28:30 +01:00
Bastiaan van der Plaat
5e7a82a853 LibWeb: Create canvas bitmap when not existing in toDataURL and toBlob 2023-09-28 13:09:25 +02:00
Aliaksandr Kalenik
dd7bba66ed LibWeb: Change viewport ownership from BrowsingContext to Navigable 2023-09-16 16:53:32 +02:00
Shannon Booth
76af9d434c LibWeb: Port HTMLCanvasElement interface from DeprecatedString to String 2023-09-05 20:36:09 -04:00
stelar7
434d95ef55 LibWeb: Add missing promise rejection in execute_async_script 2023-08-21 13:22:04 -06:00
stelar7
b0adf96eff LibWeb: Implement the timeout step of execute_async_script 2023-08-21 13:22:04 -06:00
stelar7
23b378822b LibWeb: Stub out Release Actions
This allows WPT to open the browser, and it no longer instantly crashes
2023-08-21 13:22:04 -06:00
Andreas Kling
09547ec975 LibJS: Make PrimitiveString::deprecated_string() infallible
Work towards #20449.
2023-08-09 17:09:16 +02:00
Andreas Kling
ddbe6bd7b4 Userland: Rename Core::Object to Core::EventReceiver
This is a more precise description of what this class actually does.
2023-08-06 20:39:51 +02:00
Timothy Flynn
996c020b0d Everywhere: Remove 'clang-format off' comments that are no longer needed 2023-07-08 10:32:56 +01:00
Timothy Flynn
f57310999d LibWeb: Update workarounds for the empty execution context stack
Use the new helper class to perform this workaround.
2023-07-06 15:18:50 -04:00
Aliaksandr Kalenik
7765ebb5f2 LibJS+LibWeb: Plumb local variables names to ECMAScriptFunctionObject
Saving vector of local variables names in ECMAScriptFunctionObject
will allow to get a name by index in case message of ReferenceError
needs to contain a variable name.
2023-07-05 21:03:01 +02:00
Lucas CHOLLET
b46667639f LibHTTP: Make HttpRequest return its method name as a StringView 2023-07-03 23:29:28 +02:00
Aliaksandr Kalenik
f04ae5f542 LibWeb/WebDriver: Close client connection socket when EOF is reached
Fixes the bug that currently we don't ever close webdriver client
connection socket when header "Connection: keep-alive" is specified.

This allows to run more WPT tests without running out of free file
descriptors :)
2023-06-19 09:55:47 -04:00
Aliaksandr Kalenik
857ceb215c LibWeb/WebDriver: Support resolve with callback in execute_async_script
Before execute_async_script supported returning value from script to
/execute/async caller only if script returns promise that resolves into
returned value. This change fixes execute_async_script to also support
returning value to caller using callback that is always passed to
script as a last argument.
2023-05-30 18:55:47 +02:00
kleines Filmröllchen
fc5cab5c21 Everywhere: Use MonotonicTime instead of Duration
This is easily identifiable by anyone who uses Duration::now_monotonic,
and any downstream users of that data.
2023-05-24 23:18:07 +02:00
kleines Filmröllchen
213025f210 AK: Rename Time to Duration
That's what this class really is; in fact that's what the first line of
the comment says it is.

This commit does not rename the main files, since those will contain
other time-related classes in a little bit.
2023-05-24 23:18:07 +02:00
Kemal Zebari
eda2a2f5da AK: Remove must_set() from JsonArray
Due to 582c55a, both `must_set()` and `set()` should be providing the
same behavior. Not only is that a reason to remove `must_set()`, but
it also performs erroneous behavior since it inserts an element at
a specified index instead of modifying an element at that index.
2023-05-09 06:21:34 +02:00
Cameron Youell
8134dccdc7 AK: Add new failable JsonArray::{append/set} functions
Move all old usages to the more explicit `JsonArray:must_{append/set}`
2023-04-24 09:21:51 +02:00
Linus Groh
e6be5c37c0 LibWeb/WebDriver: Handle WindowProxy in internal_json_clone_algorithm()
To test:

```console
curl http://0.0.0.0:8000/session \
  -H 'Content-Type: application/json' \
  -d '{"capabilities": {}}'
curl http://0.0.0.0:8000/session/0/execute/sync \
  -H 'Content-Type: application/json' \
  -d '{"script": "return window;", "args": []}'
```

Which should result in:

```json
{
  "value": {
    "window-fcc6-11e5-b4f8-330a88ab9d7f":
    "86307df6-e2f1-4175-85cb-77295ff90898"
  }
}
```
2023-04-20 14:41:31 -04:00
Linus Groh
b84f8fb55b LibJS: Make intrinsics getters return NonnullGCPtr
Some of these are allocated upon initialization of the intrinsics, and
some lazily, but in neither case the getters actually return a nullptr.

This saves us a whole bunch of pointer dereferences (as NonnullGCPtr has
an `operator T&()`), and also has the interesting side effect of forcing
us to explicitly use the FunctionObject& overload of call(), as passing
a NonnullGCPtr is ambigous - it could implicitly be turned into a Value
_or_ a FunctionObject& (so we have to dereference manually).
2023-04-13 14:29:42 +02:00
Aliaksandr Kalenik
05a2d1f0e0 LibWeb/WebDriver: Wait for more data to arrive if request is incomplete
Currently significant portion of requests coming to WebDriver server
fails with error while parsing json body because requests are parsed
when they are not complete yet.

This change solves this by waiting for more data to arrive if HTTP
request parser found that there is not enough data yet to parse
the whole request.

In the future we would probably want to move this logic to LibHTTP
because this problem is relevant for any HTTP server.
2023-03-26 17:56:17 +02:00
Aliaksandr Kalenik
9220cdc285 LibHTTP+WebDriver+WebServer: Return error from HTTP request parser 2023-03-26 17:56:17 +02:00
Aliaksandr Kalenik
4f496e97fe LibWeb: Add keep-alive in response headers if it present in request
This fix addresses issue where, if request headers contain
"Connection: keep-alive", we keep socket open without letting client
know that we support keep-alive connections. This can result in a
large number of open and unused sockets.
2023-03-19 22:31:59 -04:00
Aliaksandr Kalenik
f287165823 LibWeb+WebContent+WebDriver: Add WebDriver endpoint to open new window 2023-03-16 13:17:37 -04:00
Matthew Olsson
7c0c1c8f49 LibJS+LibWeb: Wrap raw JS::Cell*/& fields in GCPtr/NonnullGCPtr 2023-03-15 08:48:49 +01:00
Timothy Flynn
fc15968418 WebDriver: Fix typo in browser capabilities key parsing 2023-03-13 17:34:00 -04:00
Tim Schumacher
ae51c1821c Everywhere: Remove unintentional partial stream reads and writes 2023-03-13 15:16:20 +00:00
Tim Schumacher
d5871f5717 AK: Rename Stream::{read,write} to Stream::{read_some,write_some}
Similar to POSIX read, the basic read and write functions of AK::Stream
do not have a lower limit of how much data they read or write (apart
from "none at all").

Rename the functions to "read some [data]" and "write some [data]" (with
"data" being omitted, since everything here is reading and writing data)
to make them sufficiently distinct from the functions that ensure to
use the entire buffer (which should be the go-to function for most
usages).

No functional changes, just a lot of new FIXMEs.
2023-03-13 15:16:20 +00:00