Commit Graph

16 Commits

Author SHA1 Message Date
Karl Seguin
550fb58f3f Introduce Page (container)
Follow up to https://github.com/lightpanda-io/browser/pull/2200

This change is actually pretty mundane, but a bunch of files that used to
take a *Session (e.g. every WebAPI releaseRef and deinit) now take a *Page.

This aims to separate the 2 lifetimes currently managed by Session by moving
the "Page" lifetime to a dedicated container: Page. Ultimately, the goal is to
remove the 1-page-per-session limit of the current design. Not to explicitly
support multiple pages per session (though, that's more possible now), but
in order to better emulate Chrome where, during a navigation event, the old and
new page both exist.
2026-04-23 15:48:13 +08:00
Karl Seguin
4ff55a8cff More Worker APIs
Enable URL, AbortController and AbortSignal for Workers. Had a large impact
because Event.initTrusted was changed from taking a *Frame to taking a *Session.

Also, make WGS and Frame have a matching `dispatch` method so that it's easier
to dispatch events against an executor (inline else =>). Similarly, added
dupeString directly to executor to make migrations easier.
2026-04-22 12:47:44 +08:00
Karl Seguin
2275416505 Page -> Frame
This is to pave the way for introducing a new "Page" container, which will take
over the page lifecycle currently burdening Session. The ultimate goal of that
is to allow the Session to have multiple pages (mostly for better transitions
between pages), which is hard to do now since the Session has so much state.

This rename was aggressive, e.g. currentPage() -> currentFrame() so that, when
the new Page container is added, you won't see "currentPage()" and wonder:

  "Does 'currentPage' mean the new Page container, or the Frame (which
  used to be called Page)".
2026-04-22 08:42:18 +08:00
Karl Seguin
a8490b1803 Enable more WebAPIs for Workers
Request, Response, Headers and FormData.
2026-04-20 15:10:47 +08:00
Karl Seguin
2d20e57f80 Change all @import("...../log.zig") to const log = lp.log;
@import("lightpanda") where needed.

Would also like to do this for String, Page, Session and js which all stand out
as types that are use across the codebase.

I know that a few devs are doing this in new work and I haven't heard anyone
voice an objection.
2026-04-20 12:40:04 +08:00
Karl Seguin
4c02959596 update workers to use new arena pool 2026-04-14 12:24:09 +08:00
Karl Seguin
197de3dc0c Limit Worker API to supported types
In order for an API to be supported by workers, their dependency on *Page has
to be removed. To keep this PR smaller, we're only converting a minimum number
of APIs from Page to Execution. All other APIs should not be exposed to the
worker (better to get a FormData undefined than to try to segfault trying to
execute FormData without a page).
2026-04-14 12:24:09 +08:00
Karl Seguin
d1d561f5c1 Worker.close() 2026-04-14 12:24:09 +08:00
Karl Seguin
b3a8a7454e add error callbacks for workers 2026-04-14 12:24:09 +08:00
Karl Seguin
5e7f891546 Add unhandledPromiseRejection for Worker
Allow *Session to be injected into WebAPI for more generic webapis between
page and workers.
2026-04-14 12:24:09 +08:00
Karl Seguin
0247b21483 Improve event dispatching between/from workers 2026-04-14 12:24:08 +08:00
Karl Seguin
ce6b01f7f6 Allow structuredClone to target a different context 2026-04-14 12:24:08 +08:00
Karl Seguin
fb844a17b6 Worker WebAPI 2026-04-14 12:24:08 +08:00
Karl Seguin
951986b655 Create Worker context in snapshot
Turns out you can embed multiple contexts within a snapshot. So our snapshot
now contains the Page context (as before) but also the Worker context. This
gives us the performance benefit of snapshots and makes context creation for
pages and workers much more similar.
2026-04-14 12:24:08 +08:00
Karl Seguin
7ca3aa61e9 Make context work with Page of WGS
A context can be created for either a Page or a Worker. This removes the
Context.page field and replaces it with a Context.global union.
2026-04-14 12:24:08 +08:00
Karl Seguin
cd2bb28c6c Tweak snapshot for workers
We'll have two types of contexts: one for pages and one for workers. They'll
[probably] both be js.Context, but they'll have distinct FunctionTemplates
attached to their global. The Worker template will only contain a small subset
of the main Page's types, along with 1 or 2 of its own specific ones.

The Snapshot now creates the templates for both, so that the Env contains the
function templates for both contexts. Furthermore, having a "merged" view like
this ensures that the env.template[N] indices are consistent between the two.

However, the snapshot only attaches the Page-specific types to the snapshot
context. This allows the Page-context to be created as-is (e.g. efficiently).
The worker context will be created lazily, on demand, but from the templates
loaded into the env (since, again, the env contains templates for both).
2026-04-14 12:24:08 +08:00