blob: fa382908dfd9b2038151d42684f1803a9f803bd6 [file] [log] [blame]
<!DOCTYPE>
<html>
<script>
function loadText(blob) {
return new Promise((resolve, reject) => {
const reader = new FileReader;
reader.addEventListener("load", () => resolve(reader.result), { once: true });
reader.addEventListener("error", reject, { once: true });
reader.readAsText(blob);
});
}
function loadImage(blob) {
return new Promise((resolve, reject) => {
const image = new Image;
image.addEventListener("load", () => resolve(image), { once: true });
image.addEventListener("error", reject, { once: true });
image.src = URL.createObjectURL(blob);
});
}
function loadDocument(blob) {
return new Promise(async resolve => {
resolve(new DOMParser().parseFromString(await loadText(blob), "text/html"));
});
}
clipboardData = [];
exception = null;
async function readClipboard() {
try {
const items = await navigator.clipboard.read();
for (const item of items) {
let itemData = {};
for (const type of item.types) {
const blob = await item.getType(type);
if (type === "text/html")
itemData[type] = await loadDocument(blob);
else if (type === "image/png")
itemData[type] = await loadImage(blob);
else
itemData[type] = await loadText(blob);
}
clipboardData.push(itemData);
}
} catch (e) {
exception = e;
} finally {
webkit.messageHandlers.testHandler.postMessage("readClipboard");
}
}
</script>
<body>
</body>
</html>