Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
refactor(renderer): authorize document tasks by exact owner
ldm027b86343f89f
diff --git a/moli-renderer-v8/src/document_runtime/lifecycle.rs b/moli-renderer-v8/src/document_runtime/lifecycle.rsindex 77b7e96aa..03d7d82f5 100644--- a/moli-renderer-v8/src/document_runtime/lifecycle.rs+++ b/moli-renderer-v8/src/document_runtime/lifecycle.rs@@ -65,7 +65,7 @@ impl DocumentRuntime {owner: crate::frame_owner_model::FrameDocumentTaskOwner,) {let sender = self.stylesheet_lifecycle.task_sender.clone();- let producer = sender.bind_producer(owner, self.runtime_reset_generation());+ let producer = sender.bind_producer(owner);let completion_producer = producer.clone();self.stylesheet_lifecycle.fetchesdiff --git a/moli-renderer-v8/src/document_runtime/main_parser_continuation.rs b/moli-renderer-v8/src/document_runtime/main_parser_continuation.rsindex c48e03432..90782c397 100644--- a/moli-renderer-v8/src/document_runtime/main_parser_continuation.rs+++ b/moli-renderer-v8/src/document_runtime/main_parser_continuation.rs@@ -40,11 +40,8 @@ impl MainParserContinuationState {impl DocumentRuntime {pub(crate) fn bind_main_parser_continuation_producer(&mut self, owner: FrameDocumentTaskOwner) {- self.main_parser_continuation.producer = Some(- self.main_parser_continuation- .sender- .bind_producer(owner, self.runtime_reset_generation()),- );+ self.main_parser_continuation.producer =+ Some(self.main_parser_continuation.sender.bind_producer(owner));self.main_parser_continuation.admitted = false;}@@ -61,11 +58,6 @@ impl DocumentRuntime {owner,"phase-one parser owner must match its bound continuation producer");- assert_eq!(- producer.owner().runtime_generation(),- self.runtime_reset_generation(),- "phase-one parser generation must match its continuation producer"- );self.main_parser_continuation.phase_one_active = true;self.main_parser_continuation.admitted = false;}diff --git a/moli-renderer-v8/src/page_task_queue/main_document_runtime.rs b/moli-renderer-v8/src/page_task_queue/main_document_runtime.rsindex 642a594bd..3d7e256d2 100644--- a/moli-renderer-v8/src/page_task_queue/main_document_runtime.rs+++ b/moli-renderer-v8/src/page_task_queue/main_document_runtime.rs@@ -90,15 +90,10 @@ impl RendererPageMainDocumentRuntimeTask {fn new(root_document: RendererDocumentToken,document_owner: FrameDocumentTaskOwner,- runtime_generation: u64,action: RendererPageMainDocumentRuntimeAction,) -> Self {Self {- owner: RendererPageMainDocumentRuntimeOwner::new(- root_document,- document_owner,- runtime_generation,- ),+ owner: RendererPageMainDocumentRuntimeOwner::new(root_document, document_owner),action,}}@@ -144,7 +139,7 @@ impl RendererPageMainDocumentRuntimeRoute {}/// PageVm-stamped producer. Callers must additionally provide the exact-/// main-Document owner and runtime generation captured at task production.+/// main-Document owner captured at task production.#[derive(Clone, Debug)]pub(crate) struct RendererPageMainDocumentRuntimeSender {task_route: OwnerReadyTaskRoute<@@ -158,7 +153,6 @@ impl RendererPageMainDocumentRuntimeSender {fn send(&self,document_owner: FrameDocumentTaskOwner,- runtime_generation: u64,action: RendererPageMainDocumentRuntimeAction,) -> Result<(), RendererPageMainDocumentRuntimeRouteClosed> {self.task_route@@ -166,7 +160,6 @@ impl RendererPageMainDocumentRuntimeSender {RendererPageMainDocumentRuntimeTask::new(self.root_document,document_owner,- runtime_generation,action,),))@@ -188,7 +181,6 @@ impl RendererPageMainDocumentRuntimeSender {fn send_runtime_script_admission(&self,document_owner: FrameDocumentTaskOwner,- runtime_generation: u64,admission: RuntimeScriptAdmission,) -> Result<(), RuntimeScriptAdmission> {debug_assert_eq!(@@ -199,7 +191,6 @@ impl RendererPageMainDocumentRuntimeSender {let task = ReadyPageTask::new(RendererPageMainDocumentRuntimeTask::new(self.root_document,document_owner,- runtime_generation,RendererPageMainDocumentRuntimeAction::AdmitRuntimeScript(admission),));self.task_route@@ -219,19 +210,20 @@ impl RendererPageMainDocumentRuntimeSender {pub(crate) fn send_for_source_contract_test(&self,document_owner: FrameDocumentTaskOwner,- runtime_generation: u64,action: RendererPageMainDocumentRuntimeAction,) -> Result<(), RendererPageMainDocumentRuntimeRouteClosed> {- self.send(document_owner, runtime_generation, action)+ self.send(document_owner, action)}}-/// Producer bound to one exact main Document/runtime generation.+/// Producer bound to one exact main Document.////// Asynchronous runtime state may retain this value, and the Document-owned/// host scheduler replaces its current producer only at the synchronous/// `document.open()` owner transition. Already-created producers therefore-/// cannot rebind work to a later Document epoch.+/// cannot rebind work to a later Document. `runtime_generation` remains only+/// as transitional metadata for binding pending `PreparedScript` payloads; it+/// is not part of the Page task's authorization identity.#[derive(Clone, Debug)]pub(crate) struct RendererPageMainDocumentRuntimeProducer {sender: RendererPageMainDocumentRuntimeSender,@@ -244,8 +236,7 @@ impl RendererPageMainDocumentRuntimeProducer {&self,action: RendererPageMainDocumentRuntimeAction,) -> Result<(), RendererPageMainDocumentRuntimeRouteClosed> {- self.sender- .send(self.document_owner, self.runtime_generation, action)+ self.sender.send(self.document_owner, action)}pub(crate) fn send_runtime_script_continuation(@@ -258,11 +249,8 @@ impl RendererPageMainDocumentRuntimeProducer {&self,admission: RuntimeScriptAdmission,) -> Result<(), RuntimeScriptAdmission> {- self.sender.send_runtime_script_admission(- self.document_owner,- self.runtime_generation,- admission,- )+ self.sender+ .send_runtime_script_admission(self.document_owner, admission)}pub(crate) fn send_parser_async_module_admission(@@ -1041,7 +1029,6 @@ mod tests {.pop_front().expect("one ready parser continuation should retain one task");assert_eq!(task.owner().document_owner(), owner);- assert_eq!(task.owner().runtime_generation(), runtime_generation);assert_eq!(task.action_kind(),PageMainDocumentRuntimeActionKind::ParserOwnedModuleContinuation@@ -1068,7 +1055,6 @@ mod tests {.pop_front().expect("one native module owner event should retain one task");assert_eq!(task.owner().document_owner(), owner);- assert_eq!(task.owner().runtime_generation(), runtime_generation);assert_eq!(task.action_kind(),PageMainDocumentRuntimeActionKind::NativeModuleOwnerEvent@@ -1111,7 +1097,6 @@ mod tests {.pop_front().expect("completed source work should enter the ready source once");assert_eq!(task.owner().document_owner(), owner);- assert_eq!(task.owner().runtime_generation(), runtime_generation);let RendererPageMainDocumentRuntimeAction::ExecuteReadyPostParseWork(work) =task.into_action()else {diff --git a/moli-renderer-v8/src/page_task_queue/main_document_task_owner.rs b/moli-renderer-v8/src/page_task_queue/main_document_task_owner.rsindex 31798b6b8..9c9650a3f 100644--- a/moli-renderer-v8/src/page_task_queue/main_document_task_owner.rs+++ b/moli-renderer-v8/src/page_task_queue/main_document_task_owner.rs@@ -1,14 +1,13 @@use crate::{frame_owner_model::FrameDocumentTaskOwner, runtime::RendererDocumentToken};-/// Exact main-Document epoch shared by task families that target one live+/// Exact main-Document residence shared by task families that target one live/// parser/runtime instance.///-/// The three identity layers are intentionally kept together:+/// The two identity layers are intentionally kept together:///-/// - `root_document` rejects tasks from a retired PageVm generation;-/// - `document_owner` rejects `Document` replacement;-/// - `runtime_generation` rejects `document.open()` epochs that deliberately-/// keep the same V8 realm and PageVm.+/// - `root_document` rejects tasks from a retired PageVm document;+/// - `document_owner` rejects `Document` replacement, including+/// `document.open()` while the V8 realm and PageVm are retained.////// A task may still be selected after this owner becomes stale. Selection/// removes the task from its FIFO; the executor then compares this locator@@ -17,19 +16,16 @@ use crate::{frame_owner_model::FrameDocumentTaskOwner, runtime::RendererDocumentpub(crate) struct RendererPageMainDocumentTaskOwner {root_document: RendererDocumentToken,document_owner: FrameDocumentTaskOwner,- runtime_generation: u64,}impl RendererPageMainDocumentTaskOwner {pub(crate) const fn new(root_document: RendererDocumentToken,document_owner: FrameDocumentTaskOwner,- runtime_generation: u64,) -> Self {Self {root_document,document_owner,- runtime_generation,}}@@ -41,16 +37,11 @@ impl RendererPageMainDocumentTaskOwner {self.document_owner}- pub(crate) const fn runtime_generation(self) -> u64 {- self.runtime_generation- }-#[cfg(test)]pub(crate) const fn new_for_test(root_document: RendererDocumentToken,document_owner: FrameDocumentTaskOwner,- runtime_generation: u64,) -> Self {- Self::new(root_document, document_owner, runtime_generation)+ Self::new(root_document, document_owner)}}diff --git a/moli-renderer-v8/src/page_task_queue/main_parser_continuation.rs b/moli-renderer-v8/src/page_task_queue/main_parser_continuation.rsindex 649f78d30..79da26cd1 100644--- a/moli-renderer-v8/src/page_task_queue/main_parser_continuation.rs+++ b/moli-renderer-v8/src/page_task_queue/main_parser_continuation.rs@@ -25,7 +25,7 @@ pub(crate) enum MainParserContinuationRequest {#[derive(Clone, Copy, Debug, Eq, PartialEq)]pub(crate) struct RendererPageMainParserContinuationRouteClosed;-/// Page-scoped route that can be bound to one exact main parser epoch.+/// Page-scoped route that can be bound to one exact main parser Document.#[derive(Clone, Debug)]pub(crate) struct RendererPageMainParserContinuationSender {networking: RendererPageNetworkingRoute,@@ -46,15 +46,10 @@ impl RendererPageMainParserContinuationSender {pub(crate) fn bind_producer(&self,document_owner: FrameDocumentTaskOwner,- runtime_generation: u64,) -> RendererPageMainParserContinuationProducer {RendererPageMainParserContinuationProducer {networking: self.networking.clone(),- owner: RendererPageMainDocumentTaskOwner::new(- self.root_document,- document_owner,- runtime_generation,- ),+ owner: RendererPageMainDocumentTaskOwner::new(self.root_document, document_owner),admission: Arc::new(MainParserContinuationAdmission::default()),}}@@ -220,7 +215,7 @@ mod tests {),);let producer = RendererPageMainParserContinuationSender::new(source.route(), root_document)- .bind_producer(test_document_owner(), 5);+ .bind_producer(test_document_owner());(source, producer)}diff --git a/moli-renderer-v8/src/page_task_queue/owner_sources/conformance_tests.rs b/moli-renderer-v8/src/page_task_queue/owner_sources/conformance_tests.rsindex 1844e6e20..f04550c1f 100644--- a/moli-renderer-v8/src/page_task_queue/owner_sources/conformance_tests.rs+++ b/moli-renderer-v8/src/page_task_queue/owner_sources/conformance_tests.rs@@ -532,7 +532,6 @@ impl MainDocumentRuntimeLane {sender.send_for_source_contract_test(task_owner(sequence + 200),- sequence,RendererPageMainDocumentRuntimeAction::ContinueRuntimeScriptWork,).is_ok()@@ -2474,7 +2473,6 @@ fn unified_ready_descriptors_expose_one_fifo_head_per_typed_source() {.main_document_runtime_sender(document_token(1)).send_for_source_contract_test(task_owner(90),- 1,RendererPageMainDocumentRuntimeAction::ContinueRuntimeScriptWork,).expect("main-Document runtime task should enter the unified source set");diff --git a/moli-renderer-v8/src/page_task_queue/stylesheet_task.rs b/moli-renderer-v8/src/page_task_queue/stylesheet_task.rsindex 9a082dffd..37bdf90e8 100644--- a/moli-renderer-v8/src/page_task_queue/stylesheet_task.rs+++ b/moli-renderer-v8/src/page_task_queue/stylesheet_task.rs@@ -98,20 +98,15 @@ impl RendererPageStylesheetTaskSender {pub(crate) fn bind_producer(&self,document_owner: FrameDocumentTaskOwner,- runtime_generation: u64,) -> RendererPageStylesheetTaskProducer {RendererPageStylesheetTaskProducer {sender: self.clone(),- owner: RendererPageStylesheetTaskOwner::new(- self.root_document,- document_owner,- runtime_generation,- ),+ owner: RendererPageStylesheetTaskOwner::new(self.root_document, document_owner),}}}-/// Producer bound to one exact main Document/runtime generation.+/// Producer bound to one exact main Document.////// Async fetches clone this value at start. Rebinding the current Document/// therefore cannot retarget an already-running fetch to its replacement.@@ -299,7 +294,7 @@ impl RendererPageStylesheetTaskTestResidence {#[derive(Clone, Copy, Debug, Eq, PartialEq)]pub(crate) enum PageStylesheetNetworkingTargetEffect {- /// The exact main Document/runtime generation accepted the terminal and+ /// The exact main Document accepted the terminal and/// may have published a later parser continuation or element event.AppliedToCurrentOwner,/// The retired task retained its historical network accounting without@@ -378,7 +373,7 @@ mod tests {#[test]fn captured_element_kind_selects_the_normative_event_task_source() {let mut residence = RendererPageStylesheetTaskTestResidence::new();- let producer = residence.sender().bind_producer(document_owner(), 4);+ let producer = residence.sender().bind_producer(document_owner());producer.send_connected_style_event(ReadyConnectedStyleLoad::for_owner(diff --git a/moli-renderer-v8/src/runtime/page_turn_scheduler.rs b/moli-renderer-v8/src/runtime/page_turn_scheduler.rsindex ab42c8722..de4c07422 100644--- a/moli-renderer-v8/src/runtime/page_turn_scheduler.rs+++ b/moli-renderer-v8/src/runtime/page_turn_scheduler.rs@@ -1052,7 +1052,6 @@ mod tests {LocalWindowId(order + 1),DocumentId(order + 2),),- order + 3,),}}diff --git a/moli-renderer-v8/src/runtime/page_vm/page_main_document_runtime.rs b/moli-renderer-v8/src/runtime/page_vm/page_main_document_runtime.rsindex 781d37694..a7123a378 100644--- a/moli-renderer-v8/src/runtime/page_vm/page_main_document_runtime.rs+++ b/moli-renderer-v8/src/runtime/page_vm/page_main_document_runtime.rs@@ -72,8 +72,6 @@ impl PageVm {) -> Option<RendererPageMainDocumentRuntimeOwner> {if expected.root_document() != self.document_lifecycle.identity().document|| self.vm().current_main_document_task_owner() != Some(expected.document_owner())- || self.vm().document_runtime.runtime_reset_generation()- != expected.runtime_generation(){return None;}@@ -119,11 +117,10 @@ impl PageVm {)}RendererPageMainDocumentRuntimeAction::ContinueRuntimeScriptWork => {+ let runtime_generation = self.vm().document_runtime.runtime_reset_generation();let body_effect = self.vm_mut()- .continue_main_document_runtime_script_task_body(- owner.runtime_generation(),- );+ .continue_main_document_runtime_script_task_body(runtime_generation);PageMainDocumentRuntimeTurnAction::runtime_script_continuation(owner,PageRuntimeScriptContinuationTargetEffect::AppliedToCurrentOwner(@@ -141,8 +138,9 @@ impl PageVm {)}RendererPageMainDocumentRuntimeAction::ContinueRuntimeOwnedModule => {+ let runtime_generation = self.vm().document_runtime.runtime_reset_generation();self.vm_mut()- .begin_runtime_owned_module_continuation_turn(owner.runtime_generation());+ .begin_runtime_owned_module_continuation_turn(runtime_generation);let made_progress = self.run_ready_runtime_owned_module_script_continuation(loader).await?;@@ -157,8 +155,9 @@ impl PageVm {)}RendererPageMainDocumentRuntimeAction::ContinueParserOwnedModule => {+ let runtime_generation = self.vm().document_runtime.runtime_reset_generation();self.vm_mut()- .begin_parser_owned_module_continuation_turn(owner.runtime_generation());+ .begin_parser_owned_module_continuation_turn(runtime_generation);let task_effect = self.run_next_ready_parser_owned_document_script_action(loader).await?;diff --git a/moli-renderer-v8/src/runtime/page_vm/page_main_parser_continuation.rs b/moli-renderer-v8/src/runtime/page_vm/page_main_parser_continuation.rsindex 83c462ff6..03b087ca5 100644--- a/moli-renderer-v8/src/runtime/page_vm/page_main_parser_continuation.rs+++ b/moli-renderer-v8/src/runtime/page_vm/page_main_parser_continuation.rs@@ -28,7 +28,6 @@ impl PageVm {owner.root_document() == self.document_lifecycle.identity().document;let target_effect = if root_document_is_current&& self.vm().current_main_document_task_owner() == Some(owner.document_owner())- && self.vm().document_runtime.runtime_reset_generation() == owner.runtime_generation()&& self.vm_mut().document_runtimediff --git a/moli-renderer-v8/src/runtime/page_vm/tests/main_document_runtime.rs b/moli-renderer-v8/src/runtime/page_vm/tests/main_document_runtime.rsindex b0def2974..a1f0ccd4f 100644--- a/moli-renderer-v8/src/runtime/page_vm/tests/main_document_runtime.rs+++ b/moli-renderer-v8/src/runtime/page_vm/tests/main_document_runtime.rs@@ -19,7 +19,6 @@ async fn document_open_discards_an_already_queued_main_runtime_task() {.vm().current_main_document_task_owner().expect("old main Document owner");- let old_runtime_generation = page_vm.vm().document_runtime.runtime_reset_generation();page_vm.vm_mut().eval(r#"@@ -39,9 +38,7 @@ document.body.appendChild(staleScript);.vm().current_main_document_task_owner().expect("replacement main Document owner");- let new_runtime_generation = page_vm.vm().document_runtime.runtime_reset_generation();assert_ne!(new_document_owner, old_document_owner);- assert_ne!(new_runtime_generation, old_runtime_generation);let outcome = page_vm.run_page_main_document_runtime_body_for_test(&loader)@@ -49,10 +46,6 @@ document.body.appendChild(staleScript);.expect("the old runtime task must remain durable until its stale-discard turn");assert_eq!(outcome.action.owner().root_document(), old_root);assert_eq!(outcome.action.owner().document_owner(), old_document_owner);- assert_eq!(- outcome.action.owner().runtime_generation(),- old_runtime_generation- );assert_eq!(outcome.action.kind(),crate::page_task_queue::PageMainDocumentRuntimeActionKind::RuntimeScriptAdmission@@ -88,7 +81,6 @@ async fn document_open_discards_an_already_ready_parser_module_action() {.vm().current_main_document_task_owner().expect("old main Document owner");- let old_generation = page_vm.vm().document_runtime.runtime_reset_generation();let mut script = prepared_inline_module_for_page_vm_test(&page_vm,9091,@@ -107,8 +99,8 @@ async fn document_open_discards_an_already_ready_parser_module_action() {"document.open(); document.write('<!doctype html><body>replacement</body>'); document.close(); 'replaced'",)?;assert_ne!(- page_vm.vm().document_runtime.runtime_reset_generation(),- old_generation+ page_vm.vm().current_main_document_task_owner(),+ Some(old_owner));let outcome = page_vm@@ -120,7 +112,6 @@ async fn document_open_discards_an_already_ready_parser_module_action() {crate::page_task_queue::PageMainDocumentRuntimeActionKind::ParserOwnedModuleContinuation);assert_eq!(outcome.action.owner().document_owner(), old_owner);- assert_eq!(outcome.action.owner().runtime_generation(), old_generation);assert_eq!(outcome.action.target_effect(),crate::page_task_queue::PageMainDocumentRuntimeTargetEffect::IgnoredStaleOwner@@ -229,8 +220,6 @@ fn page_vm_replacement_discards_the_old_root_before_running_the_colliding_new_ta.vm().current_main_document_task_owner().expect("retired PageVm main Document owner");- let retired_runtime_generation =- page_vm.vm().document_runtime.runtime_reset_generation();page_vm.vm_mut().eval(r#"globalThis.__retiredMainRuntimeTaskRan = 0;@@ -266,18 +255,11 @@ document.body.appendChild(retiredScript);.vm().current_main_document_task_owner().expect("replacement PageVm main Document owner");- let current_runtime_generation =- page_vm.vm().document_runtime.runtime_reset_generation();assert_ne!(retired_root, current_root);assert_eq!(retired_owner, current_owner,"fresh PageVm owner stores should naturally reuse the same local main-Document ids");- assert_eq!(- retired_runtime_generation, current_runtime_generation,- "fresh PageVms should naturally reuse the same runtime generation"- );-// `follow_pending_location_navigation_one_turn_async()` may// return at the replacement's post-parse continuation rather// than after DCL. Establish the post-DCL producer boundary@@ -305,10 +287,6 @@ document.body.appendChild(replacementScript);.expect("retired PageVm task should consume one stale-discard turn");assert_eq!(stale.action.owner().root_document(), retired_root);assert_eq!(stale.action.owner().document_owner(), retired_owner);- assert_eq!(- stale.action.owner().runtime_generation(),- retired_runtime_generation- );assert_eq!(stale.action.target_effect(),crate::page_task_queue::PageMainDocumentRuntimeTargetEffect::IgnoredStaleOwner@@ -321,10 +299,6 @@ document.body.appendChild(replacementScript);.expect("replacement PageVm task must remain behind the retired head");assert_eq!(current.action.owner().root_document(), current_root);assert_eq!(current.action.owner().document_owner(), current_owner);- assert_eq!(- current.action.owner().runtime_generation(),- current_runtime_generation- );assert_eq!(current.action.kind(),crate::page_task_queue::PageMainDocumentRuntimeActionKind::RuntimeScriptAdmissiondiff --git a/moli-renderer-v8/src/runtime/phase_one/streaming_input.rs b/moli-renderer-v8/src/runtime/phase_one/streaming_input.rsindex 5f827821a..9e64838a2 100644--- a/moli-renderer-v8/src/runtime/phase_one/streaming_input.rs+++ b/moli-renderer-v8/src/runtime/phase_one/streaming_input.rs@@ -167,14 +167,11 @@ mod tests {);let continuation =RendererPageMainParserContinuationSender::new(networking.route(), root_document)- .bind_producer(- FrameDocumentTaskOwner::new(- FrameSchedulerLaneId(1),- LocalWindowId(2),- DocumentId(3),- ),- 0,- );+ .bind_producer(FrameDocumentTaskOwner::new(+ FrameSchedulerLaneId(1),+ LocalWindowId(2),+ DocumentId(3),+ ));(networking, continuation, wake_rx)}diff --git a/moli-renderer-v8/src/script_vm/stylesheet_page_tasks.rs b/moli-renderer-v8/src/script_vm/stylesheet_page_tasks.rsindex 199766c88..e14eb7a68 100644--- a/moli-renderer-v8/src/script_vm/stylesheet_page_tasks.rs+++ b/moli-renderer-v8/src/script_vm/stylesheet_page_tasks.rs@@ -23,7 +23,6 @@ impl ScriptVm {) -> bool {owner.root_document() == root_document&& self.current_main_document_task_owner() == Some(owner.document_owner())- && self.document_runtime.runtime_reset_generation() == owner.runtime_generation()}pub(crate) fn apply_page_stylesheet_networking_task(