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>
function close_peer_and_wait(register) {
const channel = new MessageChannel();
const events = [];
const closed = new Promise(function (resolve) {
register(channel.port1, events, resolve);
});
channel.port2.addEventListener("close", function () {
events.push("initiator");
});
channel.port2.close();
return closed.then(function () {
channel.port1.close();
return events;
});
}
promise_test(async function () {
const events = await close_peer_and_wait(function (port, events, resolve) {
port.addEventListener("close", function (event) {
events.push("listener:" + event.type + ":" + event.isTrusted);
resolve();
});
port.onclose = function (event) {
events.push("onclose:" + event.type + ":" + event.isTrusted);
};
});
assert_array_equals(
events,
["listener:close:true", "onclose:close:true"],
"close should be fired at the peer in listener registration order",
);
}, "MessagePort.close fires close at the entangled peer without start()");
promise_test(async function () {
const events = await close_peer_and_wait(function (port, events, resolve) {
port.onclose = function (event) {
events.push("onclose:" + event.isTrusted);
};
port.addEventListener("close", function (event) {
events.push("listener:" + event.isTrusted);
resolve();
});
});
assert_array_equals(
events,
["onclose:true", "listener:true"],
"onclose should keep its original event handler listener order",
);
}, "MessagePort.onclose participates in close listener ordering");
promise_test(async function () {
const channel = new MessageChannel();
const closed = new Promise(function (resolve) {
channel.port1.addEventListener("close", function (event) {
event.initEvent("mutated", true, true);
resolve(event);
});
});
channel.port2.close();
const event = await closed;
channel.port1.close();
assert_true(event.isTrusted, "host-dispatched close event should be trusted");
assert_equals(event.type, "close", "initEvent should not mutate type during dispatch");
assert_false(event.bubbles, "initEvent should not mutate bubbles during dispatch");
assert_false(event.cancelable, "initEvent should not mutate cancelable during dispatch");
}, "MessagePort close dispatch suppresses initEvent mutation while dispatching");
promise_test(async function () {
const channel = new MessageChannel();
let closeCalls = 0;
const message = new Promise(function (resolve) {
channel.port1.addEventListener("close", function () {
closeCalls++;
});
channel.port1.addEventListener("message", function (event) {
resolve(event.data);
}, { once: true });
channel.port1.start();
});
channel.port2.postMessage("payload");
assert_equals(await message, "payload");
assert_equals(closeCalls, 0, "close listener must not receive message events");
channel.port1.close();
channel.port2.close();
}, "MessagePort message dispatch filters listeners by event type");
</script>