:autofill pseudo class always returns true
It might be reasonable to always return false instead - autofill is not really possible in this environment
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/src/nwsapi.min.js" onload="NW.Dom.install"></script>
</head>
<body>
<div id="test">test</div>
<script>
const element = NW.Dom.byId("test", document)[0];
const isAutofill = NW.Dom.match(":autofill", element);
document.write("isAutofill: " + isAutofill);
</script>
</body>
</html>
Autofill pseudo class: https://developer.mozilla.org/en-US/docs/Web/CSS/:autofill
@zuzusik I am trying to reconstruct the history of these additions to the list of pseudo-class selector considered in nwsapi.
If I recall correctly the additions of these pseudo-class stems from a jsdom request to avoid breaking the process for all of the pseudo-class starting with "-webkit-" to be ignored and considered as invalid selectors, producing a "false" match but continuing the processing of the complete selector input. This was back in the days were none of these pseudo-classes was contemplated by any selectors specification.
Only later, when the "-webkit-autofill" started appearing as a possible pseudo-class selector developers realized that choice to be wrong and started to be a problem. At that point I tried to revert the code to return a "noop" instead of a "false" match result and ended up adding the lines after the existing ones while probably they should have been added before the single ":" and double "::" resolvers. Here is the relevant code lines in the sources:
// allow pseudo-elements starting with single colon (:)
// :after, :before, :first-letter, :first-line
// assert: e.type is in double-colon format, like ::after
else if ((match = selector.match(Patterns.pseudo_sng))) {
source = 'if(e.element&&e.type.toLowerCase()=="' +
':' + match[0].toLowerCase() + '"){e=e.element;' + source + '}';
}
// allow pseudo-elements starting with double colon (::)
// ::after, ::before, ::marker, ::placeholder, ::inactive-selection, ::selection, ::-webkit-<foo-bar>
// assert: e.type is in double-colon format, like ::after
else if ((match = selector.match(Patterns.pseudo_dbl))) {
source = 'if(e.element&&e.type.toLowerCase()=="' +
match[0].toLowerCase() + '"){e=e.element;' + source + '}';
}
// placeholder for parsed only no-op selectors
else if ((match = selector.match(Patterns.pseudo_nop))) {
break;
}
else {
// reset
expr = false;
status = false;
So currently that's the mess we are at. My suggestion is to change the resolver in a way it doesn't hurt us in the future when more of these sophisticated selectors will appear as valid. I am open to suggestions keeping in mind that we should absolutely mimic today's browsers functionality regarding this and if necessary have flags to let users change behaviour.
Obviously the code should check if the property yielding the true result does effectively allow for such a property and pseudo-class as we normally do for any other selectors considered valid.
At that point I tried to revert the code to return a "noop" instead of a "false" match result and ended up adding the lines after the existing ones while probably they should have been added before the single ":" and double "::" resolvers
Yeah, this seems reasonable to me - looking at the snippet you provided I agree that Patterns.pseudo_nop should go before two other conditions, otherwise :autofill will be processed by the first one (Patterns.pseudo_sng)
we should absolutely mimic today's browsers functionality regarding this
I don't think it is really possible to detect auto-fill from Javascript, other than checking if the element is returned with respective .querySelector result, so to me it makes sense to mark :autofill as never present in NWSAPI, till there will be a good way to detect auto-filled elements from JS without tapping into selector engine.