The headless browser for AI agents and web scraping
fix(js): define the FileList global so boot references stop crashing
Yi-111-a86f0ec063325
diff --git a/crates/obscura-js/js/bootstrap.js b/crates/obscura-js/js/bootstrap.jsindex be457daf..143b693f 100644--- a/crates/obscura-js/js/bootstrap.js+++ b/crates/obscura-js/js/bootstrap.js@@ -10702,10 +10702,13 @@ globalThis.__obscura_setHovered = function(el) {}};-// Build a FileList-like object: an array with the DOM's `item(i)` accessor.+// Build a FileList: indexed File entries plus the DOM's length and `item(i)`+// accessor. Real instances of the FileList global (issue #1232), not arrays,+// so `input.files instanceof FileList` holds.function _makeFileList(files) {- const list = files.slice();- Object.defineProperty(list, "item", { value: (i) => list[i] || null, enumerable: false });+ const list = Object.create(FileList.prototype);+ for (let i = 0; i < files.length; i++) list[i] = files[i];+ Object.defineProperty(list, "length", { value: files.length, enumerable: false, writable: false });return list;}function _emptyFileList() { return _makeFileList([]); }@@ -11238,6 +11241,14 @@ if (typeof File === "undefined") globalThis.File = class File extends Blob {}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; }+ 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 --git a/crates/obscura-js/src/frame.rs b/crates/obscura-js/src/frame.rsindex 1a07a324..c6f96f35 100644--- a/crates/obscura-js/src/frame.rs+++ b/crates/obscura-js/src/frame.rs@@ -1572,4 +1572,36 @@ 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")+ );+ }}