-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Use NavigatorUAData and navigator.webdriver to improve bot dete…
…ction (#1359) * Use NavigatorUAData and navigator.webdriver to improve bot detection * Use real values of brands from headless and regular chrome in tests * Reduce bundle size slightly * Remove global * Fix test setup * Opt out of bot filtering in cypress * Make _is_likely_bot an instance function on posthog, use it in cypress tests * Fix cypress imports * Code golf * More code golf * Fix testcafe tests * Treat cypress as a bot * Fix cypress chaining logic
- Loading branch information
Showing
15 changed files
with
246 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/// <reference types="cypress" /> | ||
import { start } from '../support/setup' | ||
|
||
describe('User Agent Blocking', () => { | ||
it('should pick up that our automated cypress tests are indeed bot traffic', async () => { | ||
cy.skipOn('windows') | ||
start({}) | ||
|
||
cy.window().then((win) => { | ||
const isLikelyBot = win.eval('window.posthog._is_bot()') | ||
expect(isLikelyBot).to.eql(true) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { useEffect, useState } from 'react' | ||
|
||
// Try this page with some of the following commands: | ||
// chrome --headless --disable-gpu --print-to-pdf http://localhost:3000/ua --virtual-time-budget=10000 | ||
// chrome --headless --disable-gpu --print-to-pdf http://localhost:3000/ua --virtual-time-budget=10000 --user-agent="RealHuman" | ||
|
||
export default function Home() { | ||
const [isClient, setIsClient] = useState(false) | ||
useEffect(() => { | ||
setIsClient(true) | ||
}, []) | ||
if (!isClient) { | ||
return <pre>Not client</pre> | ||
} | ||
return ( | ||
<dl> | ||
<dt>UA</dt> | ||
<dd> | ||
<code>{navigator.userAgent}</code> | ||
</dd> | ||
<dt>WebDriver</dt> | ||
<dd> | ||
<code>{String(navigator.webdriver)}</code> | ||
</dd> | ||
<dt>NavigatorUAData brands</dt> | ||
<dd> | ||
{/* eslint-disable-next-line compat/compat */} | ||
<code>{JSON.stringify((navigator as any).userAgentData?.brands)}</code> | ||
</dd> | ||
</dl> | ||
) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.