Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
<!doctype html>
<meta charset="utf-8">
<script src="/wpt/resources/testharness.js"></script>
<script src="/wpt/resources/testharnessreport.js"></script>
<script src="/wpt/resources/moli-wpt-adapter.js"></script>
<script>
const ECHO_BODY_HEX_URL = "/wpt/runtime/xhr/echo-body-hex";
const MULTIPART_CONTENT_TYPE_PREFIX = "multipart/form-data; boundary=";
function sendBody(body) {
return new Promise(function (resolve) {
const xhr = new XMLHttpRequest();
xhr.onload = function () {
resolve({ status: xhr.status, response: xhr.response });
};
xhr.open("POST", ECHO_BODY_HEX_URL);
xhr.responseType = "json";
xhr.send(body);
});
}
function asciiHex(value) {
let output = "";
for (let i = 0; i < value.length; i++) {
output += value.charCodeAt(i).toString(16).padStart(2, "0");
}
return output;
}
function utf8Hex(value) {
let output = "";
for (const byte of new TextEncoder().encode(value)) {
output += byte.toString(16).padStart(2, "0");
}
return output;
}
function bytesHex(bytes) {
let output = "";
for (const byte of bytes) {
output += byte.toString(16).padStart(2, "0");
}
return output;
}
function multipartBoundary(result) {
assert_equals(result.status, 200, "FormData binary request status");
assert_true(
result.response.content_type.startsWith(MULTIPART_CONTENT_TYPE_PREFIX + "----MoliFormDataBoundary"),
"FormData should install a multipart Content-Type with a generated boundary",
);
return result.response.content_type.slice(MULTIPART_CONTENT_TYPE_PREFIX.length);
}
promise_test(async function () {
const binaryBytes = [0x00, 0xff, 0x41, 0x80, 0x0a, 0x0d];
const data = new FormData();
data.append("prefix", "text");
data.append("binary", new Blob([new Uint8Array(binaryBytes)], { type: "application/octet-stream" }));
const result = await sendBody(data);
const boundary = multipartBoundary(result);
const expectedHex =
asciiHex(`--${boundary}\r\n`) +
asciiHex('Content-Disposition: form-data; name="prefix"\r\n\r\n') +
asciiHex("text\r\n") +
asciiHex(`--${boundary}\r\n`) +
asciiHex('Content-Disposition: form-data; name="binary"; filename="blob"\r\n') +
asciiHex("Content-Type: application/octet-stream\r\n\r\n") +
bytesHex(binaryBytes) +
asciiHex("\r\n") +
asciiHex(`--${boundary}--\r\n`);
assert_equals(
result.response.body_hex,
expectedHex,
"FormData Blob parts should preserve non-UTF-8 bytes in multipart bodies",
);
}, "XMLHttpRequest preserves non-UTF-8 bytes in FormData multipart Blob parts");
promise_test(async function () {
const data = new FormData();
data.append("carriage\rname", "carriage\rvalue");
data.append("cafe-é", "值-😀");
data.append("unicode-file", new File(["unicode-file-body"], "resume-é-😀.txt", {
type: "text/unicode",
}));
const result = await sendBody(data);
const boundary = multipartBoundary(result);
const expectedHex =
asciiHex(`--${boundary}\r\n`) +
asciiHex('Content-Disposition: form-data; name="carriage%0D%0Aname"\r\n\r\n') +
asciiHex("carriage\r\nvalue\r\n") +
asciiHex(`--${boundary}\r\n`) +
utf8Hex('Content-Disposition: form-data; name="cafe-é"\r\n\r\n') +
utf8Hex("值-😀\r\n") +
asciiHex(`--${boundary}\r\n`) +
utf8Hex('Content-Disposition: form-data; name="unicode-file"; filename="resume-é-😀.txt"\r\n') +
asciiHex("Content-Type: text/unicode\r\n\r\n") +
asciiHex("unicode-file-body\r\n") +
asciiHex(`--${boundary}--\r\n`);
assert_equals(
result.response.body_hex,
expectedHex,
"FormData multipart names, values, and filenames should escape CR and preserve UTF-8 bytes",
);
}, "XMLHttpRequest escapes CR and preserves Unicode in FormData multipart metadata");
</script>