Add EventTarget methods to navigator.connection and serviceWorker

NetworkInformation (navigator.connection) and ServiceWorkerContainer (navigator.serviceWorker) are EventTargets in real browsers. React 18 and mobile SPAs call addEventListener on them; the stubs lacked it, so the app bundle crashed with 'addEventListener is not a function' (e.g. goofish.com).
This commit is contained in:
SGavrl committed 2026-06-10 19:47:23 +00:00
1 parent ee86dbf996
commit 534de77882
2 files changed
+23 -2

No files matched your search

+21
View File
@@ -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.