feat: check if a CSS selector path identifies a unique el on webpage

This commit is contained in:
karishmas6
2024-06-05 22:48:55 +05:30
parent 40100eb495
commit 139c22ba83

View File

@@ -290,6 +290,19 @@ export const getSelectors = async (page: Page, coordinates: Coordinates) => {
return path.map((node) => node.penalty).reduce((acc, i) => acc + i, 0);
}
function unique(path: Path) {
switch (rootDocument.querySelectorAll(selector(path)).length) {
case 0:
throw new Error(
`Can't select any node with this selector: ${selector(path)}`
);
case 1:
return true;
default:
return false;
}
}
};