in src/js/webview/CSSSelectorResolver.js [92:139]
static resolve(
element: Element,
multiple: boolean,
contextSelector: string,
fieldName: string
): string[] {
// Generate candidates
let candidates = this.generateCandidates(element, MAX_DEPTH);
// Hard limit at MAX_CANDIDATES tries, for performance
candidates = candidates.slice(0, MAX_CANDIDATES);
let filteredCandidates = [];
if (!multiple) {
// Allow only candidates that return a single element
// and matching the target element
filteredCandidates = candidates.filter(candidate =>
this.isUnique(candidate, element, contextSelector)
);
} else {
// Allow all candidates that match the target element
filteredCandidates = candidates.filter(candidate =>
element.matches(candidate)
);
}
filteredCandidates = this.filterSelectors(
filteredCandidates,
fieldName,
contextSelector
);
// If none was found, return the absolute selector
if (filteredCandidates.length === 0) {
return [this.resolveAbsolute(element, contextSelector)];
}
// Rank candidates
let rankedCandidates = this.rankCandidates(
filteredCandidates,
fieldName,
contextSelector
);
// Returns the highest ranked candidate
return rankedCandidates;
}