matchesAnySelectorJs function
Builds a self-contained JS snippet that returns true when any of
selectors matches an element in the current document.
Implementation
String matchesAnySelectorJs(List<String> selectors) {
final selectorsJson = jsonEncode(selectors);
return '''
(function () {
var selectors = $selectorsJson;
for (var i = 0; i < selectors.length; i++) {
try {
if (document.querySelector(selectors[i])) return true;
} catch (e) {}
}
return false;
})();
''';
}