Closed jlowcs closed 7 months ago
Thank you for the Issue. I will list supported items for version 4 and review using es-check. It should match supported devices for regular expression "lookbehind" feature. Isbot version 3 supports engines that does not support this feature.
Do you plan on maintaining v3 with new/updated bot user agents?
That's a very good question. The non-lookbehind patterns include some false-positives. For example, a lot of android apps include the webview substring "Channel/googleplay", where the simplistic "google" substring pattern will recognise as a bot. That's why I think supporting version 3 pattern updates is not a priority.
Regular expression lookbehind is now widely supported.
Source: https://caniuse.com/?search=Lookbehind |
Instead - I might create a shorter, more simplistic and more optimistic option for engines that do not support lookbehind as a fallback. This could mitigate your case as well.
For example:
let pattern;
try {
pattern = new Regexp("(?<! cu)bot(?:[^\\w]|_|$)", "i");
} catch (error) {
pattern = /bot/i;
}
What is your opinion about this feature?
That's a very good question. The non-lookbehind patterns include some false-positives. For example, a lot of android apps include the webview substring "Channel/googleplay", where the simplistic "google" substring pattern will recognise as a bot. That's why I think supporting version 3 pattern updates is not a priority.
Regular expression lookbehind is now widely supported.
True, although Safari only started supporting it in 2023...
A quarter of our users seem to be on older browser versions (ie over 4 versions old), for which we serve a less optimized bundle. As we're providing a platform for social change, we want to be mindful of the fact that not everyone have access to modern browsers, but we still want them to be able to use the platform.
Instead - I might create a shorter, more simplistic and more optimistic option for engines that do not support lookbehind as a fallback. This could mitigate your case as well.
For example:
let pattern; try { pattern = new Regexp("(?<! cu)bot(?:[^\\w]|_|$)", "i"); } catch (error) { pattern = /bot/i; }
What is your opinion about this feature?
I like this idea!
https://github.com/omrilotan/isbot/pull/237
This changeset adds a fallback for engines that do not support lookbehind in regular expressions. This fallback is less accurate but catches ~78% of bots with less than 1% false-positive. It is also exposed as "isbotNaive" export.
Happy if you would take a look
The only regretful side effect is the pattern can not be tree-shaken for users who don't use the "isbot" named export.
The only regretful side effect is the pattern can not be tree-shaken for users who don't use the "isbot" named export.
Would using a IIFE fix that?
export const pattern = (() => {
try {
return new RegExp(expression, "i");
} catch (error) {
return naiveExpression;
}
})();
No, because iife run anyways it will be included in all output versions. I'm not very worried about this, most of usage is for "isbot" function anyway.
No, because iife run anyways it will be included in all output versions. I'm not very worried about this, most of usage is for "isbot" function anyway.
I think it depends on whether you set "sideEffects": false
in your package.json
, but I might be wrong.
No, because iife run anyways it will be included in all output versions. I'm not very worried about this, most of usage is for "isbot" function anyway.
I think it depends on whether you set
"sideEffects": false
in yourpackage.json
, but I might be wrong.
It's about what runs in-scope and what has to run on "module load". I was able to separate the two exports by building both the string and the regex as individual exports.
Version 4.4.0 should be okay when importing isbot.
import { isbot } from "isbot"
I greatly appreciate your involvement in this issue. It helped me reach a better outcome.
Thank you for fixing this so quickly, this makes it possible for us to upgrade to v4 again. :)
@omrilotan It appears this is still an issue for Safari versions that don't support lookbehind (In my case, Safari 15.5).
@bfaulk96 appologies for the delay. Proposed resolution: #243
@bfaulk96 appologies for the delay. Proposed resolution: #243
No worries! Thanks for the quick turnaround, though! #243 looks like it would do the trick!
Resolution of isbot@5 tested on Safari 15.6
Can confirm, isbot@5 is working now for my Safari 15.5 use-case. Thanks again for the quick turnaround on that!
Steps to reproduce
install es-check
create a file with the regex from the release:
run
es-check es2017
on that fileExpected behaviour
It should pass the check, or the README should explicitely say that older browsers are not supported.
Actual behaviour
It does not pass the check