Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
fix(modules): expose inline import meta base URLs
ldm0c689e4adf834
diff --git a/moli-renderer-v8/src/document_runtime/script_scheduling/module_facade.rs b/moli-renderer-v8/src/document_runtime/script_scheduling/module_facade.rsindex 5c7a68c74..b7b8c42ad 100644--- a/moli-renderer-v8/src/document_runtime/script_scheduling/module_facade.rs+++ b/moli-renderer-v8/src/document_runtime/script_scheduling/module_facade.rs@@ -294,12 +294,6 @@ impl DocumentRuntime {.native_compiled_module(entry_id)}- pub(crate) fn native_module_url_for(&self, module: v8::Local<'_, v8::Module>) -> Option<Url> {- self.script_lifecycle- .scripts()- .native_module_url_for(module)- }-pub(crate) fn mark_native_module_instantiated(&mut self, entry_id: ModuleEntryId) {self.script_lifecycle.scripts_mut()diff --git a/moli-renderer-v8/src/host/scripts.rs b/moli-renderer-v8/src/host/scripts.rsindex f090a27ea..f0a23897e 100644--- a/moli-renderer-v8/src/host/scripts.rs+++ b/moli-renderer-v8/src/host/scripts.rs@@ -687,13 +687,6 @@ impl HostScriptScheduler {self.module_owner.native_compiled_module(entry_id)}- pub(crate) fn native_module_url_for(- &self,- module: v8::Local<'_, v8::Module>,- ) -> Option<url::Url> {- self.module_owner.native_module_url_for(module)- }-pub(crate) fn mark_native_module_instantiated(&mut self, entry_id: ModuleEntryId) {self.module_owner.mark_native_module_instantiated(entry_id);}diff --git a/moli-renderer-v8/src/module_runtime.rs b/moli-renderer-v8/src/module_runtime.rsindex 49df6be11..9b1278a45 100644--- a/moli-renderer-v8/src/module_runtime.rs+++ b/moli-renderer-v8/src/module_runtime.rs@@ -592,12 +592,6 @@ impl ModuleOwnerState {.map(|record| record.compiled_module().clone())}- pub(crate) fn native_module_url_for(&self, module: v8::Local<'_, v8::Module>) -> Option<Url> {- self.document_modulator- .module_key_for(module)- .map(|key| key.url().clone())- }-pub(crate) fn mark_native_module_instantiated(&mut self, entry_id: ModuleEntryId) {self.document_modulator.mark_instantiated(entry_id);}diff --git a/moli-renderer-v8/src/module_runtime/graph.rs b/moli-renderer-v8/src/module_runtime/graph.rsindex 612e21687..03104ae4a 100644--- a/moli-renderer-v8/src/module_runtime/graph.rs+++ b/moli-renderer-v8/src/module_runtime/graph.rs@@ -2328,7 +2328,7 @@ fn module_script_inline_tree_job_for_owner(let (record, identity) = match vm.compile_native_module_record(key.clone(),&source,- &root.source_url,+ &root.base_url,&root.fetch_metadata,) {Ok(result) => result,diff --git a/moli-renderer-v8/src/module_runtime/host_callbacks.rs b/moli-renderer-v8/src/module_runtime/host_callbacks.rsindex b4e31af1f..7e9a4f83a 100644--- a/moli-renderer-v8/src/module_runtime/host_callbacks.rs+++ b/moli-renderer-v8/src/module_runtime/host_callbacks.rs@@ -35,16 +35,10 @@ pub(crate) unsafe extern "C" fn initialize_import_meta_object_callback(meta: v8::Local<'_, v8::Object>,) {v8::callback_scope!(unsafe scope, context);- let Some(host_ptr) = context_host_ptr_from_global_bridge(scope) else {- return;- };- let Some(module_url) = (unsafe { &*host_ptr }).native_module_url_for(module) else {- return;- };- let Some(value) = v8_string(scope, module_url.as_str()) else {+ let Ok(module_url) = v8::Local::<v8::String>::try_from(module.get_resource_name(scope)) else {return;};- let _ = ImportMetaDeclaration::new(value).initialize(scope, meta);+ let _ = ImportMetaDeclaration::new(module_url).initialize(scope, meta);}pub(crate) fn dynamic_import_callback<'s, 'i>(diff --git a/moli-renderer-v8/src/module_runtime/modulator.rs b/moli-renderer-v8/src/module_runtime/modulator.rsindex ee9d8e39b..45c8f31cc 100644--- a/moli-renderer-v8/src/module_runtime/modulator.rs+++ b/moli-renderer-v8/src/module_runtime/modulator.rs@@ -655,14 +655,6 @@ impl NativeDocumentModulator {.set_record_state_for_entry(self.core.entry(entry_id), ModuleRecordState::Evaluated);}- pub(crate) fn module_key_for(- &self,- module: v8::Local<'_, v8::Module>,- ) -> Option<&ModuleMapKey> {- self.module_entry_id_for(module)- .map(|entry_id| self.entry(entry_id).effective_key())- }-pub(crate) fn module_source_for(&self,module: v8::Local<'_, v8::Module>,diff --git a/moli-renderer-v8/src/runtime/page_vm/tests/mod.rs b/moli-renderer-v8/src/runtime/page_vm/tests/mod.rsindex d7e8d2819..028e610bc 100644--- a/moli-renderer-v8/src/runtime/page_vm/tests/mod.rs+++ b/moli-renderer-v8/src/runtime/page_vm/tests/mod.rs@@ -11951,15 +11951,19 @@ async fn stream_declared_controller_and_writer_surface_ignores_reflection_and_spasync fn parser_inline_module_runs_from_parser_after_parsing_order() {run_page_vm_async_test(async move {let loader = crate::network::ResourceRequestClient::new(&FetchConfig::default()).expect("loader");+ let document_url = Url::parse(+ "https://example.com/page.html?case=inline-module#document-fragment",+ )+ .expect("document URL");let mut page_vm = test_page_vm_with_loader_and_document_url(&loader,Vec::new(),- Url::parse("https://example.com/page.html").expect("document URL"),+ document_url.clone(),);let script = prepared_inline_module_for_page_vm_test(&page_vm,9002,- "globalThis.__inlineParserModuleExecuted = (globalThis.__inlineParserModuleExecuted ?? 0) + 1; export const value = 1;",+ "globalThis.__inlineParserModuleExecuted = (globalThis.__inlineParserModuleExecuted ?? 0) + 1; globalThis.__inlineParserModuleUrl = import.meta.url; export const value = 1;",);let parser_module_work = install_parser_module_defer_work(&mut page_vm, script);@@ -11995,6 +11999,14 @@ async fn parser_inline_module_runs_from_parser_after_parsing_order() {"1","parser after-parsing release should evaluate the prewarmed inline graph once");+ assert_eq!(+ page_vm+ .vm_mut()+ .eval("globalThis.__inlineParserModuleUrl")+ .expect("read inline module URL after page task"),+ document_url.as_str(),+ "an inline module must expose its document base URL, not its internal module-map key"+ );}).await;}diff --git a/moli-renderer-v8/src/script_vm/tests/mod.rs b/moli-renderer-v8/src/script_vm/tests/mod.rsindex c72770d14..64d35b1ce 100644--- a/moli-renderer-v8/src/script_vm/tests/mod.rs+++ b/moli-renderer-v8/src/script_vm/tests/mod.rs@@ -8668,7 +8668,9 @@ async fn child_inline_parser_module_executes_from_registered_pending_script() {frame.srcdoc = `<script>parent.__childInlineParserModuleEvents.push("before");<\/script><script type="module">- parent.__childInlineParserModuleEvents.push("module:" + (globalThis === self));+ parent.__childInlineParserModuleEvents.push(+ "module:" + (globalThis === self) + ":" + import.meta.url + ":" + import.meta.resolve("./x")+ );globalThis.__childInlineParserModuleValue = 42;<\/script><script>parent.__childInlineParserModuleEvents.push("after:" + String(globalThis.__childInlineParserModuleValue));<\/script>@@ -8747,7 +8749,7 @@ async fn child_inline_parser_module_executes_from_registered_pending_script() {assert_eq!(vm.eval("__childInlineParserModuleEvents.join('|')").expect("child inline parser module events should evaluate"),- "before|after:undefined|module:true"+ "before|after:undefined|module:true:http://child-inline-module.test/:http://child-inline-module.test/x");}diff --git a/vendor/v8-152.2.0/src/module.rs b/vendor/v8-152.2.0/src/module.rsindex 857b87526..b43a7249f 100644--- a/vendor/v8-152.2.0/src/module.rs+++ b/vendor/v8-152.2.0/src/module.rs@@ -211,6 +211,7 @@ where}unsafe extern "C" {+ fn v8__Module__GetResourceName(this: *const Module) -> *const Value;fn v8__Module__GetStatus(this: *const Module) -> ModuleStatus;fn v8__Module__GetException(this: *const Module) -> *const Value;fn v8__Module__GetModuleRequests(this: *const Module) -> *const FixedArray;@@ -323,6 +324,21 @@ pub enum ModuleStatus {}impl Module {+ /// If this is a source text module, returns the resource name passed to its+ /// [`ScriptOrigin`](crate::ScriptOrigin). If this is a synthetic module,+ /// returns the name passed to [`Module::create_synthetic_module`].+ #[inline(always)]+ pub fn get_resource_name<'s>(+ &self,+ scope: &PinScope<'s, '_>,+ ) -> Local<'s, Value> {+ unsafe {+ scope+ .cast_local(|_| v8__Module__GetResourceName(self))+ .unwrap()+ }+ }+/// Returns the module's current status.#[inline(always)]pub fn get_status(&self) -> ModuleStatus {diff --git a/vendor/v8-152.2.0/src/module_ext.cc b/vendor/v8-152.2.0/src/module_ext.ccindex 87f6da197..bc7b001e0 100644--- a/vendor/v8-152.2.0/src/module_ext.cc+++ b/vendor/v8-152.2.0/src/module_ext.cc@@ -7,6 +7,10 @@ using namespace support;extern "C" {+const v8::Value* v8__Module__GetResourceName(const v8::Module& self) {+ return local_to_ptr(self.GetResourceName());+}+MaybeBool v8__Module__SetSyntheticModuleExportUninitialized(const v8::Module& self,v8::Isolate* isolate,