feat: add isAutomatedBrowser helper to detect automated browsers - #497
feat: add isAutomatedBrowser helper to detect automated browsers#497aidenybai wants to merge 5 commits into
Conversation
…lenium Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
commit: |
Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>
Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>
There was a problem hiding this comment.
2 issues found across 2 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/react-grab/src/utils/is-automated-browser.ts">
<violation number="1" location="packages/react-grab/src/utils/is-automated-browser.ts:27">
P2: Hard-coding a single `$cdc_` key misses other ChromeDriver-injected `$cdc_*` markers. Use a prefix scan on document keys to preserve detection coverage.</violation>
<violation number="2" location="packages/react-grab/src/utils/is-automated-browser.ts:36">
P2: Cached detection cannot be revalidated, so `isAutomatedBrowser()` can return a stale false/true for the rest of the session. Match other cached utils by adding an optional `shouldRevalidate` reset path.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| markers.__fxdriver_evaluate || | ||
| markers.__webdriver_script_function || | ||
| // ChromeDriver injects this oddly-named helper array on document. | ||
| markers.$cdc_asdjflasutopfhvcZLmcfl_ || |
There was a problem hiding this comment.
P2: Hard-coding a single $cdc_ key misses other ChromeDriver-injected $cdc_* markers. Use a prefix scan on document keys to preserve detection coverage.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/react-grab/src/utils/is-automated-browser.ts, line 27:
<comment>Hard-coding a single `$cdc_` key misses other ChromeDriver-injected `$cdc_*` markers. Use a prefix scan on document keys to preserve detection coverage.</comment>
<file context>
@@ -0,0 +1,40 @@
+ markers.__fxdriver_evaluate ||
+ markers.__webdriver_script_function ||
+ // ChromeDriver injects this oddly-named helper array on document.
+ markers.$cdc_asdjflasutopfhvcZLmcfl_ ||
+ markers.$chrome_asyncScriptInfo,
+ );
</file context>
| export const isAutomatedBrowser = (): boolean => { | ||
| cachedIsAutomatedBrowser ??= | ||
| hasAutomationNavigatorSignal() || hasAutomationGlobal() || hasWebdriverDocumentMarker(); | ||
| return cachedIsAutomatedBrowser; | ||
| }; |
There was a problem hiding this comment.
P2: Cached detection cannot be revalidated, so isAutomatedBrowser() can return a stale false/true for the rest of the session. Match other cached utils by adding an optional shouldRevalidate reset path.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/react-grab/src/utils/is-automated-browser.ts, line 36:
<comment>Cached detection cannot be revalidated, so `isAutomatedBrowser()` can return a stale false/true for the rest of the session. Match other cached utils by adding an optional `shouldRevalidate` reset path.</comment>
<file context>
@@ -0,0 +1,40 @@
+ typeof navigator !== "undefined" &&
+ (navigator.webdriver === true || /HeadlessChrome/i.test(navigator.userAgent));
+
+export const isAutomatedBrowser = (): boolean => {
+ cachedIsAutomatedBrowser ??=
+ hasAutomationNavigatorSignal() || hasAutomationGlobal() || hasWebdriverDocumentMarker();
</file context>
| export const isAutomatedBrowser = (): boolean => { | |
| cachedIsAutomatedBrowser ??= | |
| hasAutomationNavigatorSignal() || hasAutomationGlobal() || hasWebdriverDocumentMarker(); | |
| return cachedIsAutomatedBrowser; | |
| }; | |
| export const isAutomatedBrowser = (shouldRevalidate?: boolean): boolean => { | |
| if (shouldRevalidate) { | |
| cachedIsAutomatedBrowser = undefined; | |
| } | |
| cachedIsAutomatedBrowser ??= | |
| hasAutomationNavigatorSignal() || hasAutomationGlobal() || hasWebdriverDocumentMarker(); | |
| return cachedIsAutomatedBrowser; | |
| }; |
Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/react-grab/src/utils/is-automated-browser.ts">
<violation number="1" location="packages/react-grab/src/utils/is-automated-browser.ts:27">
P2: Hard-coding a single `$cdc_` key misses other ChromeDriver-injected `$cdc_*` markers. Use a prefix scan on document keys to preserve detection coverage.</violation>
<violation number="2" location="packages/react-grab/src/utils/is-automated-browser.ts:36">
P2: Cached detection cannot be revalidated, so `isAutomatedBrowser()` can return a stale false/true for the rest of the session. Match other cached utils by adding an optional `shouldRevalidate` reset path.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>
Summary
Adds an
isAutomatedBrowser()utility toreact-grabthat detects whether the library is running inside an automated/headless browser (Playwright, Puppeteer, Selenium/WebDriver), and uses it to label the version-check telemetry source.Changes
is-automated-browser.ts— detects automated browsers.log-intro.ts— when fetching the latest version, the request'ssourcequery param is nowautomated-browserinstead ofbrowserwhen an automated browser is detected:What it detects
navigator.webdriver === true(W3C-standard flag set by all WebDriver-based tools) andHeadlessChromein the user agent.__playwright__,__pwInitScripts), Puppeteer (__puppeteer__), generic CDP (domAutomation,domAutomationController), and Selenium IDE (_Selenium_IDE_Recorder,_selenium,callSelenium).__selenium_unwrapped,__webdriver_evaluate,$cdc_*, etc.Notes
is-mac.ts/is-next-project-runtime.ts).navigator/document.Summary by cubic
Adds
isAutomatedBrowser()toreact-grabto detect automated/headless browsers and label version-check telemetry. Detection now covers navigator signals, common automation globals, and WebDriver document markers; it’s SSR-safe and memoized.New Features
navigator.webdriver,HeadlessChromeUA, automation globals (Playwright/Puppeteer/Selenium), and WebDriver document markers.sourcetoautomated-browserwhen automation is detected.Refactors
revalidateoption; kept SSR guards and memoization.Written for commit adf9ec1. Summary will update on new commits.