Skip to content

The headless browser for AI agents and web scraping

fix(js): preserve FileList iteration on current main

SGavrl716826c1e554
diff --cc crates/obscura-js/js/bootstrap.js
index 143b693f,be457daf..a6ac3479
--- a/crates/obscura-js/js/bootstrap.js
+++ b/crates/obscura-js/js/bootstrap.js
@@@ -11241,14 -11238,6 +11241,15 @@@ if (typeof File === "undefined") global
}
get [Symbol.toStringTag]() { return "File"; }
};
+// Issue #1232: `typeof FileList` was `undefined`, so apps that reference it
+// while booting crash with a ReferenceError. Not directly constructible,
+// matching Chrome (`new FileList()` throws "Illegal constructor").
+if (typeof FileList === "undefined") globalThis.FileList = class FileList {
+ constructor() { throw new TypeError("Illegal constructor"); }
+ item(i) { const v = this[i]; return v === undefined ? null : v; }
++ [Symbol.iterator]() { return Array.prototype[Symbol.iterator].call(this); }
+ get [Symbol.toStringTag]() { return "FileList"; }
+};
// A FormData value keeps Blob/File objects as-is (the multipart serializer reads
// their bytes); every other value is coerced to a string per the Fetch spec.
function _isFormBlob(v) {
diff --cc crates/obscura-js/src/frame.rs
index c6f96f35,1a07a324..c97ae1ad
--- a/crates/obscura-js/src/frame.rs
+++ b/crates/obscura-js/src/frame.rs
@@@ -1572,36 -1572,4 +1572,70 @@@ mod tests
assert!(!frame.is_same_origin_as("null"));
assert!(!frame.is_same_origin_as("https://parent.example"));
}
+
+ #[test]
+ fn file_list_global_exists_and_input_files_is_instance() {
+ // Issue #1232: `typeof FileList` was `undefined`, crashing apps that
+ // reference it while booting.
+ let mut rt = page(
+ "https://example.com/",
+ "<html><body><input type=file id=f></body></html>",
+ );
+ assert_eq!(
+ rt.evaluate("typeof FileList").unwrap(),
+ serde_json::json!("function")
+ );
+ assert_eq!(
+ rt.evaluate("Object.prototype.toString.call(document.getElementById('f').files)")
+ .unwrap(),
+ serde_json::json!("[object FileList]")
+ );
+ assert_eq!(
+ rt.evaluate("document.getElementById('f').files instanceof FileList")
+ .unwrap(),
+ serde_json::json!(true)
+ );
+ assert_eq!(
+ rt.evaluate("document.getElementById('f').files.length").unwrap(),
+ serde_json::json!(0.0)
+ );
+ assert_eq!(
+ rt.evaluate("(() => { try { new FileList(); return 'no-throw'; } catch (e) { return e.name + ': ' + e.message; } })()").unwrap(),
+ serde_json::json!("TypeError: Illegal constructor")
+ );
+ }
++
++ #[test]
++ fn file_list_iteration_preserves_uploaded_files() {
++ let mut rt = page(
++ "https://example.com/",
++ "<html><body><input type=file id=f multiple></body></html>",
++ );
++ let result = rt.evaluate(r#"(() => {
++ const input = document.getElementById('f');
++ const empty = [...input.files].length;
++ __obscura_setInputFiles(input, [
++ {name: 'first.txt', type: 'text/plain', b64: 'YQ=='},
++ {name: 'second.txt', type: 'text/plain', b64: 'Yg=='}
++ ]);
++ const files = input.files;
++ const names = [];
++ for (const file of files) names.push(file.name);
++ const iterator = files[Symbol.iterator]();
++ return {
++ empty,
++ spread: [...files].map(file => file.name),
++ names,
++ sameFile: [...files][0] === files.item(0),
++ iterableIterator: iterator[Symbol.iterator]() === iterator
++ };
++ })()"#).unwrap();
++ assert_eq!(result, serde_json::json!({
++ "empty": 0,
++ "spread": ["first.txt", "second.txt"],
++ "names": ["first.txt", "second.txt"],
++ "sameFile": true,
++ "iterableIterator": true
++ }));
++ }
}