The headless browser for AI agents and web scraping
Add EventTarget methods to navigator.connection and serviceWorker
SGavrl534de778822f
diff --git a/crates/obscura-js/js/bootstrap.js b/crates/obscura-js/js/bootstrap.jsindex 8db55ff3..1ba9463c 100644--- a/crates/obscura-js/js/bootstrap.js+++ b/crates/obscura-js/js/bootstrap.js@@ -2469,7 +2469,7 @@ globalThis.navigator = {vendor: "Google Inc.", product: "Gecko", productSub: "20030107",doNotTrack: null,deviceMemory: 8,- connection: { effectiveType: "4g", rtt: 50, downlink: 10, saveData: false },+ connection: { effectiveType: "4g", rtt: 50, downlink: 10, saveData: false, onchange: null, addEventListener(){}, removeEventListener(){}, dispatchEvent(){return true;} },get webdriver() { return false; },pdfViewerEnabled: true,get plugins() {@@ -2518,7 +2518,7 @@ globalThis.navigator = {},toJSON() { return {brands:this.brands,mobile:this.mobile,platform:this.platform}; },},- serviceWorker: { ready: Promise.resolve(), register(){return Promise.resolve();}, getRegistrations(){return Promise.resolve([]);}, controller: null },+ serviceWorker: { ready: Promise.resolve(), register(){return Promise.resolve();}, getRegistrations(){return Promise.resolve([]);}, controller: null, oncontrollerchange: null, onmessage: null, addEventListener(){}, removeEventListener(){}, dispatchEvent(){return true;} },mediaDevices: {enumerateDevices() {return Promise.resolve([diff --git a/crates/obscura-js/src/runtime.rs b/crates/obscura-js/src/runtime.rsindex 22daca0d..92908d79 100644--- a/crates/obscura-js/src/runtime.rs+++ b/crates/obscura-js/src/runtime.rs@@ -2357,6 +2357,27 @@ mod tests {/// Setting an ARIA reflection property must write through to the/// underlying attribute so frameworks that toggle state via/// `el.ariaExpanded = 'true'` actually update the DOM.+ /// Regression: React 18 / mobile SPAs (e.g. goofish.com) call+ /// addEventListener on navigator.connection (NetworkInformation) and+ /// navigator.serviceWorker (ServiceWorkerContainer). Both are EventTargets+ /// in real browsers; missing the method crashed the app bundle with+ /// "addEventListener is not a function".+ #[test]+ fn navigator_eventtarget_stubs_expose_add_event_listener() {+ let mut rt = setup_runtime("<div></div>");+ let result = rt+ .evaluate(+ r#"+ return [+ typeof navigator.connection.addEventListener,+ typeof navigator.serviceWorker.addEventListener,+ ];+ "#,+ )+ .unwrap();+ assert_eq!(result, serde_json::json!(["function", "function"]));+ }+/// Regression test for #285: DDoS-Guard's challenge calls/// `t.insertAdjacentText(...)` and dies with `TypeError: ... is not a/// function` because `Element.prototype.insertAdjacentText` was missing.