Commit Graph

1558 Commits

Author SHA1 Message Date
Pierre Tachoire
671dbcfd55 Merge pull request #470 from lightpanda-io/resove-module
Some checks are pending
e2e-test / zig build release (push) Waiting to run
e2e-test / puppeteer-perf (push) Blocked by required conditions
e2e-test / demo-scripts (push) Blocked by required conditions
wpt / web platform tests (push) Waiting to run
wpt / perf-fmt (push) Blocked by required conditions
zig-test / zig build dev (push) Waiting to run
zig-test / zig test (push) Waiting to run
zig-test / perf-fmt (push) Blocked by required conditions
browser: fix module URL resolution
2025-03-17 11:33:59 +01:00
Pierre Tachoire
087a7b5f3c browser: use *const Page with fetchModule 2025-03-17 09:58:31 +01:00
Pierre Tachoire
229844d399 browser: use *const Script with evalScript 2025-03-17 09:51:01 +01:00
Pierre Tachoire
36081653b0 Merge pull request #472 from lightpanda-io/linux_aarch64
Some checks failed
e2e-test / zig build release (push) Has been cancelled
wpt / web platform tests (push) Has been cancelled
zig-test / zig build dev (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
e2e-test / puppeteer-perf (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
wpt / perf-fmt (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled
ci: use ubuntu 24.04
2025-03-15 10:40:09 +01:00
Pierre Tachoire
9811c5d577 ci: use ubuntu 24.04 2025-03-15 10:24:34 +01:00
Pierre Tachoire
4394186dc3 Merge pull request #469 from lightpanda-io/linux_aarch64
Linux aarch64 build
2025-03-15 10:17:42 +01:00
Pierre Tachoire
725b48d8aa ci: fix install params for linux 2025-03-15 10:01:46 +01:00
Pierre Tachoire
3fd8347943 browser: fix module URL resolution 2025-03-14 19:02:33 +01:00
Pierre Tachoire
5e7c26c34b dockerfile: add ARCH parameter 2025-03-14 17:27:17 +01:00
Pierre Tachoire
d7019264a2 docker: upgrade ubuntu 2025-03-14 14:51:05 +01:00
Pierre Tachoire
ade9fa5d0e ci: add linux aarch64 to the nightly build 2025-03-14 14:38:05 +01:00
Pierre Tachoire
f84c4393b9 ci: upgrade zig-v8 version 2025-03-14 14:37:38 +01:00
Pierre Tachoire
48d01c0ab5 Merge pull request #465 from lightpanda-io/inspector-cache-debug
Some checks are pending
e2e-test / zig build release (push) Waiting to run
e2e-test / puppeteer-perf (push) Blocked by required conditions
e2e-test / demo-scripts (push) Blocked by required conditions
wpt / web platform tests (push) Waiting to run
wpt / perf-fmt (push) Blocked by required conditions
zig-test / zig build dev (push) Waiting to run
zig-test / zig test (push) Waiting to run
zig-test / perf-fmt (push) Blocked by required conditions
don't generate debug js file on release
2025-03-14 11:52:30 +01:00
Pierre Tachoire
aca01d81d6 cdp: use .zig-cache to save js script debug files 2025-03-14 11:41:21 +01:00
Pierre Tachoire
6a0b154d67 cdp: dump runtime js only in debug mode 2025-03-14 11:41:20 +01:00
Pierre Tachoire
7ce69987d5 Merge pull request #463 from karlseguin/page_arena
Optimize memory usage
2025-03-14 10:17:41 +01:00
Karl Seguin
3fe28d5441 Optimize memory usage
The two bigger changes here are:

1- The http_client has been moved from the Session to the Browser, allowing
   its connection pool to be re-used across multiple sessions

2- The browser now has a page_arena which is used for all page-level allocation
   and which can be re-used between pages (currently retains 1MB of memory).
   Previously, pages uses an arena that was tied to the lifetime of the page,
   thus it could not be re-used.

Using the Bench allocator for zig-js-runtime, allocated bytes went from
1347037879 to 834932438 (in a RUNS=1000 of puppeteer demo).

Various other changes to try to simplify the API and remove the possibility
of invalid states. For example, session.newPage() now includes the logic for
page.start() so that there should now never be a page that wasn't started.
2025-03-12 13:38:22 +08:00
Pierre Tachoire
43f42f9ca0 Merge pull request #461 from lightpanda-io/ci-playwright
Some checks failed
e2e-test / zig build release (push) Has been cancelled
wpt / web platform tests (push) Has been cancelled
zig-test / zig build dev (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
e2e-test / puppeteer-perf (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
wpt / perf-fmt (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled
ci: add e2e test w/ playwright connection
2025-03-11 10:11:08 +01:00
Pierre Tachoire
3e288f1fcf Merge pull request #462 from lightpanda-io/upgrade-jsruntime
upgrade vendor/zig-js-runtime
2025-03-11 10:10:06 +01:00
Pierre Tachoire
8ccd75fdfb upgrade vendor/zig-js-runtime 2025-03-11 09:53:33 +01:00
Pierre Tachoire
fd6aa6e54e ci: add e2e test w/ playwright connection 2025-03-11 09:52:11 +01:00
Pierre Tachoire
4802a2ce82 Merge pull request #460 from karlseguin/playwright
Remove CDP FrameId
2025-03-11 08:41:39 +01:00
Karl Seguin
e3409a27e7 fix test 2025-03-11 10:51:40 +08:00
Karl Seguin
5182edce6f Remove CDP FrameId
I don't know if FrameId is related to an <iframe>, and whether each Page has
1 implicit "frame". But, playwright seems to treat frameId and targetId as
interchangeable, and chrome seems to agree (at leas to some degree); chrome will
return a targetId and reuse that value for the frameId.

So the simplest solution is just to remove our concept of a frameId and use
targetId exclusively. This doesn't seem to cause any issues with puppeteer.
2025-03-11 10:37:43 +08:00
Pierre Tachoire
763d8d025e Merge pull request #453 from lightpanda-io/loop-reset
Some checks failed
e2e-test / zig build release (push) Waiting to run
e2e-test / puppeteer-perf (push) Blocked by required conditions
e2e-test / demo-scripts (push) Blocked by required conditions
wpt / web platform tests (push) Waiting to run
wpt / perf-fmt (push) Blocked by required conditions
zig-test / zig build dev (push) Waiting to run
zig-test / zig test (push) Waiting to run
zig-test / perf-fmt (push) Blocked by required conditions
nightly build / build-linux-x86_64 (push) Has been cancelled
nightly build / build-macos-aarch64 (push) Has been cancelled
Reset loop event after page stop.
2025-03-10 16:07:34 +01:00
Pierre Tachoire
a3045c9808 ci: run demo's puppeteer scripts 2025-03-10 15:59:46 +01:00
Pierre Tachoire
6b78b011b7 upgrade zig-jsruntime 2025-03-10 15:59:46 +01:00
Pierre Tachoire
bd7b84e136 loop: reset the loop after page end 2025-03-10 15:59:46 +01:00
Pierre Tachoire
2a9bab3f13 Merge pull request #450 from lightpanda-io/cdp-playwright
cdp: improve playwright support
2025-03-10 15:56:41 +01:00
Pierre Tachoire
6ca1e6c6dd cdp: let the inspector return the response
When a command is forwarded to the inspector, it handles directly the
reponse to the message.
2025-03-10 14:57:10 +01:00
Pierre Tachoire
f3a1a6a191 cdp: add a Page.getFrameTree unit test 2025-03-10 14:57:10 +01:00
Pierre Tachoire
675932c65b cdp: improve playwright support
The getTargetInfo result must return a `targetInfo` key.

Here is an example returned by Chrome:
```json
{
  "id": 16,
  "result": {
    "targetInfo": {
      "targetId": "d93a1bbc-f906-4bbb-bb4d-a2285234b091",
      "type": "browser",
      "title": "",
      "url": "",
      "attached": true,
      "canAccessOpener": false
    }
  }
}
```
2025-03-10 14:57:05 +01:00
Pierre Tachoire
708abb0e30 Merge pull request #459 from lightpanda-io/browser_context
Make CDP server more authoritative with respect to IDs
2025-03-10 14:49:53 +01:00
Karl Seguin
9de84aee2e Don't send CDP result when message is forward to inspector.
Rely on inspector to send the result, otherwise we'll send 2 responses to the
same message (one ourselves and one from the inspector), which Playwright does
not like.
2025-03-10 14:34:32 +01:00
Karl Seguin
adb8779d00 allow Target.getTargetInfo to be called without parameters 2025-03-10 14:34:32 +01:00
Karl Seguin
fbb0e675f5 send attach events before result 2025-03-10 14:34:32 +01:00
Karl Seguin
a3e2b5246e Make CDP server more authoritative with respect to IDs
The TL;DR is that this commit enforces the use of correct IDs, introduces a
BrowserContext, and adds some CDP tests.

These are the ids we need to be aware of when talking about CDP:
- id
- browserContextId
- targetId
- sessionId
- loaderId
- frameId

The `id` is the only one that _should_ originate from the driver. It's attached
to most messages and it's how we maintain a request -> response flow: when
the server responds to a specific message, it echo's back the id from the
requested message. (As opposed to out-of-band events sent from the server which
won't have an `id`). When I say "id" from this point forward, I mean every id
except for this req->res id.

Every other id is created by the browser.

Prior to this commit, we didn't really check incoming ids from the driver. If
the driver said "attachToTarget" and included a targetId, we just assumed that
this was the current targetId. This was aided by the fact that we only used
hard-coded IDS. If _we_ only "create" a frameId of "FRAME-1", then it's tempting
to think the driver will only ever send a frameId of "FRAME-1".

The issue with this approach is that _if_ the browser and driver fall out of sync
and there's only ever 1 browserContextId, 1 sessionId and 1 frameId, it's not
impossible to imagine cases where we behave on the thing.

Imagine this flow:
- Driver asks for a new BrowserContext
- Browser says OK, your browserContextId is 1
- Driver, for whatever reason, says close browserContextId 2
- Browser says, OK, but it doesn't check the id and just closes the only
  BrowserContext it knows about (which is 1)

By both re-using the same hard-coded ids, and not verifying that the ids sent
from the client correspond to the correct ids, any issues are going to be hard
to debug.

Currently LOADER_ID and FRAEM_ID are still hard-coded. Baby steps.
2025-03-10 14:34:32 +01:00
Pierre Tachoire
ccacac0597 Merge pull request #458 from karlseguin/serialized_writes
Some checks are pending
e2e-test / zig build release (push) Waiting to run
e2e-test / puppeteer (push) Blocked by required conditions
wpt / web platform tests (push) Waiting to run
wpt / perf-fmt (push) Blocked by required conditions
zig-test / zig build dev (push) Waiting to run
zig-test / zig test (push) Waiting to run
zig-test / perf-fmt (push) Blocked by required conditions
Serialize socket writes + consider client pending completions when sh…
2025-03-10 10:24:57 +01:00
Karl Seguin
ca230aa230 Serialize socket writes + consider client pending completions when shutting down
Previously, we could have multiple in-flight messages from the server to a
single client. This isn't safe and can lead to message interleaving. While
write / send are atomic, they are only atomic for the N bytes which they write,
which may not be the entire buffer. Consider this writeAll function:

```
pub fn writeAll(socket: socket_t, bytes: []const u8) !void {
    var index: usize = 0;
    while (index < bytes.len) {
        index += try posix.write(socket, bytes[index..]);
    }
}
```

If we're trying to send "abc123", this could take anywhere from 1 to 6 calls
to posix.write (it would take 6 calls, for example, if every call to
posix.write only wrote a single byte). Now if you're trying to write other data
to this same socket at the same time, messages _will_ get interleaved.

In order for this to work, the client now has a send_queue (doubly linked list).
When one message is sent, it sends the next.

In addition to the above change, the Client is now self-contained with respect
to its lifetime. This is necessary so that completions which come in AFTER our
concept of its lifetime ends, can still be processed. I think all types that
receive completions need to follow this model. This relies on the fact that
kqueue (which I know for a fact) and io_uring (which people seem to imply) handle
socket shutdown properly. It's still a bit messy because of timeout and not
wanting to wait until timeout to accept new connections, but needing to wait
until timeout to cleanup the client.

The self-contained nature of Client makes it difficult to test as a generic. I
removed Client(T). Tests now use real sockets. Some tests had to be removed
because they're too difficult to test over a real connection :(
2025-03-07 20:29:57 +08:00
Pierre Tachoire
7b775d2ad7 Merge pull request #452 from lightpanda-io/katie-lpd-patch-1
Update README.md
2025-03-04 17:16:34 +01:00
Pierre Tachoire
c5397bfbe2 Merge pull request #448 from karlseguin/set_cookie
Some checks failed
e2e-test / zig build release (push) Has been cancelled
wpt / web platform tests (push) Has been cancelled
zig-test / zig build dev (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
e2e-test / puppeteer (push) Has been cancelled
wpt / perf-fmt (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled
Add Set-Cookie parsing
2025-03-04 13:20:33 +01:00
Karl Seguin
9fec6ebc66 fix typo, improve comment, add 1 test case 2025-03-04 19:46:36 +08:00
Pierre Tachoire
6bc38c5782 Merge pull request #455 from lightpanda-io/upgrade-zig-azync-io
upgrade vendor/zig-async-io
2025-03-04 11:37:30 +01:00
Pierre Tachoire
7f9d585d7f upgrade vendor/zig-async-io 2025-03-04 11:29:17 +01:00
Pierre Tachoire
0b14d36c95 Merge pull request #454 from lightpanda-io/upgrade-zig-jsruntime
upgrade vendor/zig-js-runtime
2025-03-04 11:07:26 +01:00
Pierre Tachoire
e22ca2d082 upgrade vendor/zig-js-runtime 2025-03-03 15:37:43 +01:00
katie-lpd
52a70cb7f5 Update README.md
A really important visual change in the readme :)
2025-03-01 19:43:28 +01:00
Karl Seguin
a00d1d068a Cookie with SameSite=None is only valid when Secure 2025-02-27 16:47:39 +08:00
Pierre Tachoire
6ae4ed9fc3 Merge pull request #449 from karlseguin/longer_timeout
Some checks failed
e2e-test / zig build release (push) Has been cancelled
wpt / web platform tests (push) Has been cancelled
zig-test / zig build dev (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
e2e-test / puppeteer (push) Has been cancelled
wpt / perf-fmt (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled
allow longer timeouts (u8 -> u16)
2025-02-27 09:11:25 +01:00
Karl Seguin
6f5028612a add cookie jar 2025-02-27 16:09:10 +08:00