browser
browser copied to clipboard
Refactor CDP
This includes / is built on top of https://github.com/lightpanda-io/browser/pull/408
CDP is now a struct, with a cleaner separation between Server, Client and CDP. Server <-> Client <-> CDP -> Browser. The CDP instance is the state.
Optimized how cdp results and events are sent to the client - only a single allocation is now required.
Each CDP message is now processed with an arena, which is re-used for each message. Small ad-hoc message-specific allocations, like the aux_data
should now be more efficient.
Tried to remove some panics and undefines, or at least reduce the time that a field is undefined. Related, tried to remove the need for stable pointers (i.e. Browser.init
now returns a Browser
, rather than needing to be given a *Browser
).
Improved parsing of CDP messages from the client.
Removed the newly added browser.currentPage()
, since the cdp already has directly access to the session. (browser.currentPage()
would make it harder to implement the "TODO allow multiple sessions per browser.")
Failed to get any unit test coverage from CDP, but i think it's important to do as there's more and more logic being added to it. Part of the blocker is global types. I'd consider introducing a global mock Browser/Session:
const Browser = if (builtin.is_test) MockBrowser else @import("../browser/browser.zig").Browser;
But I haven't given up hope on being able to quickly start a lightweight jsruntime.Env in unit tests.
To get a sense of the changes, I think you can look at dom.discardSearchResults
which shows:
1 - how to get typed params
2 - how to access / modifity the state
3 - how to write a results