Inconsistent selectors in Chrome and Firefox
I know that library not maintained anymore, but hope that some day author will fix the issue
Accidently I have discovered that in some cases Chrome and Firefox generate different optimal selectors for same element. After debugging I found the problem in findAttributesPattern function. The problem in the way Array.sort function works in different browsers.
In my case in that line https://github.com/autarc/optimal-select/blob/722d220d2dc54d78121d610a69f6544c2e116721/src/match.js#L139 attributes variable is
0: class
1: data-css
class: class
data-css: data-css
length: 2
[[Prototype]]: NamedNodeMap
Object.keys(attributes) returns identical array ['0', '1'], but when sort callback function called in Chrome values are curr = '1', next = '0', but in Firefox curr = '0', next = '1'. So, at the end following logic:
if (nextPos === -1) {
if (currPos === -1) {
return 0;
}
return -1;
}
return currPos - nextPos;
works differently and sortedKeys in Chrome will be ['1', '0'], but in Firefox ['0', '1'].
Additional information:
-
selectfunction called with default settings,priorityvariable is
0: "id"
1: "class"
2: "href"
3: "src"
length: 4
您好,我最近比较忙,无法亲自回复您的邮件。我如果我看到您的邮件,我会尽快给您回复。