🐛 Fix clipboard getType error when no allowed types found (#8609)

When clipboard items have types that don't match the allowed types
list, the filtering results in an empty array. Calling getType with
undefined throws a NotFoundError. This change adds a check for null/undefined
types and filters them from the result.

Signed-off-by: Andrey Antukh <niwi@niwi.nz>
This commit is contained in:
Andrey Antukh
2026-03-13 08:24:36 +01:00
committed by GitHub
parent e7e6303184
commit eecb51ecc1

View File

@@ -135,7 +135,7 @@ function sortItems(a, b) {
export async function fromNavigator(options) {
options = options || {};
const items = await navigator.clipboard.read();
return Promise.all(
const result = await Promise.all(
Array.from(items).map(async (item) => {
const itemAllowedTypes = Array.from(item.types)
.filter(filterAllowedTypes(options))
@@ -155,9 +155,15 @@ export async function fromNavigator(options) {
}
const type = itemAllowedTypes.at(0);
if (type == null) {
return null;
}
return item.getType(type);
}),
);
return result.filter((item) => !!item);
}
/**