-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat: store browser / HTTP client fingerprint in Session #3646
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
51876d2
fix(core): make Session.retire() permanently mark the session as unus…
barjin 81dfe06
refactor(browser-crawler): retire browsers via context pipeline cleanup
barjin bcd87b0
refactor(core)!: drop EventEmitter dependency from SessionPool
barjin f593fa2
feat(types): add SessionFingerprint interface
barjin bb9ed89
feat(core): store fingerprint on Session
barjin 1caf6be
feat(browser-pool): persist fingerprint on session
barjin 05726cc
Merge branch 'v4' into feat/session-fingerprint
barjin 690a8e5
chore: revert unwanted changes in upgrading guide
barjin 1dfcda2
feat(http-client): thread session fingerprint through sendRequest
barjin 3cfd2d1
feat(impit-client): apply session fingerprint best-effort
barjin 546adfc
refactor(http-client): pass session through CustomFetchOptions
barjin 195d4e9
refactor(types)!: narrow SessionFingerprint to browser/platform/device
barjin f609f0c
refactor(types)!: rename browserFingerprint to details
barjin c810ba4
refactor(http-client): pass fingerprint instead of session to fetch
barjin ed7f86c
feat(impit-client): bump impit to ^0.14.0 and randomize impersonation…
barjin 8888ebc
feat(core): default SessionFingerprint at session creation
barjin a9fc52b
refactor(types)!: make SessionFingerprint hints-only
barjin be3b26e
Merge branch 'v4' into feat/session-fingerprint
barjin fa3ae2d
chore: bump `impit`, update docs
barjin 3ac943f
feat: discard host OS with `Session` fingerprints
barjin 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 hidden or 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 hidden or 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,33 @@ | ||
| import type { SessionFingerprint } from '@crawlee/types'; | ||
|
|
||
| /** | ||
| * (browser, platform, device) combinations that correspond to setups people | ||
| * actually run. Anything not listed here (e.g. `edge` on android, `safari` on | ||
| * windows, `desktop` mobile platforms) is left out so a randomized default | ||
| * never produces a fingerprint that would itself be a giveaway. | ||
| */ | ||
| const PROFILES_BY_PLATFORM = [ | ||
| { browser: 'chrome', platform: 'windows', device: 'desktop' }, | ||
| { browser: 'firefox', platform: 'windows', device: 'desktop' }, | ||
| { browser: 'edge', platform: 'windows', device: 'desktop' }, | ||
| { browser: 'chrome', platform: 'macos', device: 'desktop' }, | ||
| { browser: 'firefox', platform: 'macos', device: 'desktop' }, | ||
| { browser: 'safari', platform: 'macos', device: 'desktop' }, | ||
| { browser: 'edge', platform: 'macos', device: 'desktop' }, | ||
| { browser: 'chrome', platform: 'linux', device: 'desktop' }, | ||
| { browser: 'firefox', platform: 'linux', device: 'desktop' }, | ||
| { browser: 'chrome', platform: 'android', device: 'mobile' }, | ||
| { browser: 'firefox', platform: 'android', device: 'mobile' }, | ||
| { browser: 'safari', platform: 'ios', device: 'mobile' }, | ||
| ] as const; | ||
|
|
||
| /** | ||
| * Build a {@apilink SessionFingerprint} whose `platform` matches the host OS | ||
| * and whose `browser`/`device` are randomized within the realistic profiles for | ||
| * that platform. Used by {@apilink SessionPool} as the default fingerprint for | ||
| * freshly created sessions; callers can override by passing their own | ||
| * `fingerprint` in `sessionOptions`. | ||
| */ | ||
| export function createDefaultSessionFingerprint(): SessionFingerprint { | ||
| return { ...PROFILES_BY_PLATFORM[Math.floor(Math.random() * PROFILES_BY_PLATFORM.length)] }; | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
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.
Is there a good reason to try to match the host OS? Is it not possible to impersonate a completely different one well enough?
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.
This is legacy Crawlee v3 behaviour
crawlee/packages/browser-pool/src/fingerprinting/utils.ts
Lines 42 to 55 in ab34886
With e.g.
impit, you can emulate any OS well enough; it's not the case with browsers (e.g., system fonts leak the OS, and there isn't much you can do about it).Also, since the interface is now explicitly best-effort, I wouldn't see this as much of an issue, really ⬇️
crawlee/packages/http-client/src/base-http-client.ts
Line 31 in fa3ae2d
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.
These two points actually make me think that the default fingerprint should just not mention the OS at all and let the "consumer" decide.
Alternatively, we could rotate the OS so that there can be more variety in the generated fingerprints. And the consumer is still free to ignore the hint if they don't know how to impersonate a particular OS.
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.
Fair, you're right that the OS-stickyness is rather
BrowserPool's problem. I dropped the host-OS check here, let's see if this breaks anything