cobalt/web/src/lib/clipboard.ts
wukko 39752b2c5f
web/Omnibox: improve pasting links from clipboard
- `text/uri-list` type is now accepted (such as clipboard data from bluesky)
- http links are now allowed (such as those from rednote)
- rednote share link is properly extracted
2025-01-20 21:26:55 +06:00

18 lines
528 B
TypeScript

const allowedLinkTypes = new Set(["text/plain", "text/uri-list"]);
export const pasteLinkFromClipboard = async () => {
const clipboard = await navigator.clipboard.read();
if (clipboard?.length) {
const clipboardItem = clipboard[0];
for (const type of clipboardItem.types) {
if (allowedLinkTypes.has(type)) {
const blob = await clipboardItem.getType(type);
const blobText = await blob.text();
return blobText;
}
}
}
}