Source code

Revision control

Copy as Markdown

Other Tools

<!doctype html>
<html>
<title>Remove dusty-dir-handle</title>
<head>
<script src="/resources/testharness.js"></script>
</head>
<body>
<div id="log"></div>
<script>
const params = new URLSearchParams(window.location.search);
const channelName = params.get("channel");
if (!channelName) {
// On irrecoverable errors, window is closed: parent should check this.
window.close();
throw new Error("Unknown channel name");
}
const opName = params.get("op");
if (!opName || "remove" != opName) {
// On irrecoverable errors, window is closed: parent should check this.
window.close();
throw new Error("Unknown operation name");
}
const channel = new BroadcastChannel(channelName);
const dirHandleName = "dusty-dir-handle-" + channelName;
channel.onmessage = async ev => {
if (ev.data == "cleanup") {
channel.postMessage("done");
}
};
window.addEventListener("load", async () => {
try {
const rootDir = await navigator.storage.getDirectory();
// Let's do some clean up!
await rootDir.removeEntry(dirHandleName, { recursive: true });
channel.postMessage("200 OK");
} catch (err) {
channel.postMessage(err.message);
}
});
</script>
</body>
</html>