-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: expose detectors and separate detect and collect functions #144
Merged
Merged
Changes from 7 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
a153850
make it better
Le0Developer 1e5294a
add collect and detectors arguments to collect and detect
Le0Developer 89004ed
collect browser info
Le0Developer 6fe07cb
remove dependence on browser apis
Le0Developer 036e711
not used
Le0Developer b16e8f5
fix wrong access
Le0Developer a218454
Merge branch 'main' into feat/better-api
Le0Developer 2056ef4
fix merge
Le0Developer b4eebbc
fix circular import
Le0Developer 9111960
add type dependency between components and detectors
Le0Developer 980248c
style
Le0Developer 6f4063e
split browser info source
Le0Developer 8664514
move small sources into index.ts
Le0Developer 7efa6d8
remove unused function wrapper
Le0Developer 78cab34
Merge branch 'main' into feat/better-api
Le0Developer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -1,10 +1,23 @@ | ||
import { BotKind, BrowserKind, ComponentDict, DetectorResponse, State } from '../types' | ||
import { BotKind, BrowserEngineKind, BrowserKind, ComponentDict, DetectorResponse, State } from '../types' | ||
|
||
export function detectPluginsLengthInconsistency({ | ||
pluginsLength, | ||
browser: { browserKind, isAndroid }, | ||
android, | ||
browserKind, | ||
browserEngineKind, | ||
}: ComponentDict): DetectorResponse { | ||
if (pluginsLength.state !== State.Success) return | ||
if (browserKind !== BrowserKind.Chrome || isAndroid) return | ||
if ( | ||
pluginsLength.state !== State.Success || | ||
android.state !== State.Success || | ||
browserKind.state !== State.Success || | ||
browserEngineKind.state !== State.Success | ||
) | ||
return | ||
if ( | ||
browserKind.value !== BrowserKind.Chrome || | ||
android.value || | ||
browserEngineKind.value !== BrowserEngineKind.Chromium | ||
) | ||
return | ||
if (pluginsLength.value === 0) return BotKind.HeadlessChrome | ||
} |
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { BotKind, ComponentDict, DetectorResponse, State } from '../types' | ||
|
||
export function detectRTT({ rtt, browser: { isAndroid } }: ComponentDict): DetectorResponse { | ||
if (rtt.state !== State.Success) return | ||
export function detectRTT({ rtt, android }: ComponentDict): DetectorResponse { | ||
if (rtt.state !== State.Success || android.state !== State.Success) return | ||
// Rtt is 0 on android webview | ||
if (isAndroid) return | ||
if (android.value) return | ||
if (rtt.value === 0) return BotKind.HeadlessChrome | ||
} |
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { BotKind, ComponentDict, DetectorResponse, State } from '../types' | ||
|
||
export function detectWindowSize({ windowSize, browser: { documentFocus } }: ComponentDict): DetectorResponse { | ||
if (windowSize.state !== State.Success) return false | ||
export function detectWindowSize({ windowSize, documentFocus }: ComponentDict): DetectorResponse { | ||
if (windowSize.state !== State.Success || documentFocus.state !== State.Success) return false | ||
const { outerWidth, outerHeight } = windowSize.value | ||
// When a page is opened in a new tab without focusing it right away, the window outer size is 0x0 | ||
if (!documentFocus) return | ||
if (!documentFocus.value) return | ||
if (outerWidth === 0 && outerHeight === 0) return BotKind.HeadlessChrome | ||
} |
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,5 @@ | ||
import { isAndroid } from '../utils/browser' | ||
|
||
export default function collectIsAndroid(): boolean { | ||
return isAndroid() | ||
} | ||
Finesse marked this conversation as resolved.
Show resolved
Hide resolved
|
Le0Developer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { BrowserEngineKind } from '../types' | ||
import { getBrowserEngineKind } from '../utils/browser' | ||
|
||
export default function collectBrowserEngineKind(): BrowserEngineKind { | ||
return getBrowserEngineKind() | ||
} |
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,6 @@ | ||
import { BrowserKind } from '../types' | ||
import { getBrowserKind } from '../utils/browser' | ||
|
||
export default function collectBrowserKind(): BrowserKind { | ||
return getBrowserKind() | ||
} |
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,5 @@ | ||
import { getDocumentFocus } from '../utils/browser' | ||
|
||
export default function hasDocumentFocus(): boolean { | ||
return getDocumentFocus() | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, remove
.value
from enums.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also @Le0Developer please, merge new changes from
main