Skip to content

fingerprint camouflage #129

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

Open
wants to merge 110 commits into
base: main
Choose a base branch
from

Conversation

3-Tokisaki-Kurumi
Copy link

@3-Tokisaki-Kurumi 3-Tokisaki-Kurumi commented May 10, 2025

Pull Request:添加浏览器指纹伪装功能
PR: Add Browser Fingerprint Spoofing Feature
描述 / Description
本PR为pydoll库添加了全面的浏览器指纹伪装功能,让用户轻松地在自动化浏览过程中伪装浏览器指纹。该功能可以有效避免被网站检测为自动化工具,增强隐私保护,提高爬虫成功率。
This PR adds comprehensive browser fingerprint spoofing functionality to the pydoll library, allowing users to easily disguise their browser fingerprints during automated browsing. This feature effectively prevents detection by websites as automation tools, enhances privacy protection, and improves web scraping success rates.
核心功能 / Core Features
已实现以下核心功能:
The following core features have been implemented:
🎭 完整的指纹生成系统
多维度伪装:支持 UserAgent、WebGL、Canvas、Audio、Screen、Navigator 等多维度指纹伪装
智能生成器:FingerprintGenerator 类生成随机但真实的指纹数据
配置化定制:通过 FingerprintConfig 支持操作系统、浏览器类型、语言等个性化配置
🚀 一键启用设计
只需在创建浏览器时设置 enable_fingerprint_spoofing=True 即可启用指纹伪装:

Chrome 浏览器

browser = Chrome(enable_fingerprint_spoofing=True)

Edge 浏览器

browser = Edge(enable_fingerprint_spoofing=True)

🎯 全局指纹管理器
单例模式:FingerprintManager 全局管理器,方便不同模块间共享指纹信息
指纹持久化:支持保存和加载指纹配置,确保会话一致性
多浏览器支持:同时支持 Chrome 和 Edge 浏览器
🔧 自动 JavaScript 注入
深度伪装:自动注入 JavaScript 保护代码,覆盖浏览器原生API
无缝集成:通过 CDP (Chrome DevTools Protocol) 自动在每个页面加载前注入
检测防护:移除 navigator.webdriver 等自动化检测标记
解决的问题 / Problems Solved
✅ 反爬识别:解决了自动化浏览中被反爬系统识别的问题
✅ 隐私保护:增强了用户隐私保护能力
✅ 操作稳定性:提高了在防指纹网站上的操作稳定性
✅ 指纹唯一性:确保不同浏览器实例生成不同的指纹
变更类型 / Change Type
[x] 新功能(增加功能且向后兼容)/ New feature (backward compatible)
[ ] Bug 修复(修复向后兼容性问题)/ Bug fix (backward compatible)
[ ] 破坏性变更(导致现有功能不可用)/ Breaking change
[x] 文档更新 / Documentation update
[ ] 重构(无功能变化)/ Refactoring
[ ] 性能改进 / Performance improvement
[x] 测试(添加缺失的测试或修正现有测试)/ Tests
[x] 构建或 CI/CD 相关变更 / Build or CI/CD changes
技术实现概述 / Technical Implementation
本功能通过以下模块实现:
This feature is implemented through the following modules:

  1. 🏗️ 核心模块架构
    pydoll/fingerprint/
    ├── init.py # 模块导出和全局管理器
    ├── models.py # 数据模型(Fingerprint, FingerprintConfig)
    ├── generator.py # 指纹生成器(FingerprintGenerator)
    ├── injector.py # JavaScript注入器(FingerprintInjector)
    ├── manager.py # 指纹管理器(FingerprintManager)
    ├── browser_options.py # 浏览器选项管理器扩展
    └── browser.py # 增强的Chrome和Edge浏览器类
  2. 🎲 指纹生成逻辑
    真实性保证:基于真实浏览器统计数据生成指纹
    随机化算法:确保每次生成的指纹都是唯一的
    一致性维护:相关属性之间保持逻辑一致性
  3. 🔄 JavaScript 注入机制
    页面级注入:使用 Page.addScriptToEvaluateOnNewDocument
    API 覆盖:覆盖 Navigator、WebGL、Canvas、Audio 等关键 API
    时序控制:确保在页面脚本执行前完成注入
    测试方法 / Testing Methods
    该功能通过以下方式进行了全面测试:
    This functionality has been comprehensively tested through the following methods:
    功能测试 / Functional Testing
    from pydoll.fingerprint.browser import Chrome, Edge
    from pydoll.fingerprint import FingerprintConfig

1. 基础功能测试

browser = Chrome(enable_fingerprint_spoofing=True)
async with browser:
tab = await browser.start()
await tab.go_to("https://fingerprintjs.github.io/fingerprintjs/")

2. 自定义配置测试

config = FingerprintConfig(
browser_type="chrome",
preferred_os="windows",
enable_webgl_spoofing=True,
enable_canvas_spoofing=True
)
browser = Chrome(enable_fingerprint_spoofing=True, fingerprint_config=config)

3. 多实例唯一性测试

browser1 = Chrome(enable_fingerprint_spoofing=True)
browser2 = Chrome(enable_fingerprint_spoofing=True)

验证两个实例生成不同指纹

检测抵抗测试 / Detection Resistance Testing
在以下常见指纹检测网站进行测试验证:
✅ FingerprintJS Demo
✅ AmIUnique.org
✅ BrowserLeaks.com
✅ WhatIsMyBrowser.com
测试清单 / Test Checklist
[x] 单元测试已添加/更新 / Unit tests added/updated
[x] 集成测试已添加/更新 / Integration tests added/updated
[x] 所有现有测试通过 / All existing tests pass
[x] 功能演示示例完整 / Functional demo examples complete
使用示例 / Usage Examples
最简单的使用方式 / Simplest Usage

一键启用指纹伪装

browser = Chrome(enable_fingerprint_spoofing=True)

async with browser:
tab = await browser.start()
await tab.go_to("https://example.com")
# 自动应用指纹伪装,无需额外操作

高级用法 / Advanced Usage
from pydoll.fingerprint import FingerprintManager, FingerprintConfig, FINGERPRINT_MANAGER

1. 手动控制指纹

fingerprint = FINGERPRINT_MANAGER.generate_new_fingerprint('chrome')
print(f"指纹ID: {fingerprint.user_agent}")

2. 自定义配置

config = FingerprintConfig(
preferred_os="windows",
preferred_languages=["zh-CN", "en-US"],
min_screen_width=1920,
enable_webgl_spoofing=True
)

browser = Chrome(enable_fingerprint_spoofing=True, fingerprint_config=config)

下一步计划 / Next Steps
🔄 增加指纹模板库,支持更多场景
📱 添加更多指纹设备支持
🛡️ 进一步增强对高级指纹检测的抵抗能力
💾 优化指纹持久化存储机制

Copy link

codecov bot commented May 10, 2025

Codecov Report

Attention: Patch coverage is 91.53226% with 42 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pydoll/fingerprint/manager.py 73.17% 22 Missing ⚠️
pydoll/browser/chromium/base.py 48.27% 15 Missing ⚠️
pydoll/browser/managers/browser_options_manager.py 84.61% 4 Missing ⚠️
pydoll/fingerprint/generator.py 99.24% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@3-Tokisaki-Kurumi
Copy link
Author

这些代码风格问题(空行空格、文件末尾换行等)不影响功能实现。考虑到当前 PR 的主要目的是添加指纹伪装功能,建议先审查功能有效性,这些微小的格式问题可以在后续优化。

@3-Tokisaki-Kurumi
Copy link
Author

只是测试分支没有测试到,但是不影响使用

@thalissonvs
Copy link
Member

Hi @3-Tokisaki-Kurumi , thank you so much for you contribution!

To maintain consistency with the rest of the code, we only need to translate what's necessary into English

@3-Tokisaki-Kurumi
Copy link
Author

3-Tokisaki-Kurumi commented May 15, 2025

你好@3-Tokisaki-Kurumi,非常感谢您的贡献!

为了与其余代码保持一致,我们只需要将必要的内容翻译成英语

Thank you for your attention. I will translate the necessary content into English

@3-Tokisaki-Kurumi
Copy link
Author

3-Tokisaki-Kurumi commented May 17, 2025

你好@3-Tokisaki-Kurumi,非常感谢您的贡献!

为了与其余代码保持一致,我们只需要将必要的内容翻译成英语

现在我已经将必要的内容和注释翻译成英语,您可以审阅一下,之后我会继续贡献更优化的代码

Now I have translated the necessary content and comments into English, you can review them, and I will continue to contribute more optimized code afterwards

@thalissonvs
Copy link
Member

Hi @3-Tokisaki-Kurumi,

Sorry for the delay. I'm currently finalizing version 2 of Pydoll, which will introduce breaking changes. Once it's done, we can move forward with your contribution, as a few more adjustments will be needed. I appreciate your understanding

@3-Tokisaki-Kurumi
Copy link
Author

你好@3-Tokisaki-Kurumi

抱歉耽搁了。我目前正在最终完成 Pydoll 的 2.0 版本,这将引入一些重大更改。完成后,我们就可以继续处理您的贡献,因为还需要进行一些调整。感谢您的理解。

OK,期待你的Pydoll v2,感谢您带来了一个强大的自动化工具,等待你的更改之后我们可以继续处理此贡献

OK, Looking forward to your Pydoll v2. Thank you for bringing us a powerful automation tool. We are waiting for your changes before we can proceed with this contribution

@3-Tokisaki-Kurumi
Copy link
Author

占位,准备继续完成该贡献

Position occupied, ready to continue completing the contribution

@3-Tokisaki-Kurumi
Copy link
Author

3-Tokisaki-Kurumi commented Jun 13, 2025

你好@3-Tokisaki-Kurumi

抱歉耽搁了。我目前正在最终完成 Pydoll 的 2.0 版本,这将引入一些重大更改。完成后,我们就可以继续处理您的贡献,因为还需要进行一些调整。感谢您的理解。

现在是最新的指纹伪装功能,你可以查看一下代码,如果需要,之后我会继续贡献

Now it's the latest fingerprint camouflage feature. You can review the code and if needed, I will continue to contribute in the future

@thalissonvs
Copy link
Member

Hello! Once again, thank you very much for your efforts, I truly appreciate your contribution. However, I just noticed one thing: you didn't follow the Commitizen convention, which is required for release generation.

Before I can review your PR, could you please update your commit history to follow the guidelines described in this link?

You can do that by running the following commands:

git rebase -i HEAD~<number_of_commits_to_edit>
# Replace 'pick' with 'reword' for each commit
# Then rewrite each commit message using the Commitizen format

After that, force-push your changes. Also, everything must be in english. Thank you!

@thalissonvs thalissonvs self-requested a review June 15, 2025 00:21
@thalissonvs thalissonvs added the enhancement New feature or request label Jun 15, 2025
@3-Tokisaki-Kurumi
Copy link
Author

@thalissonvs
Hello, thank you for your correction. I have updated my submission history to follow this [link]( https://github.com/autoscrape-labs/pydoll/blob/main/CONTRIBUTING.md )The guidelines described in the document have been forcibly pushed, and now you can review my PR. Thank you for your review

您好,感谢您的纠正,我已经更新了我的的提交历史记录以遵循此链接中描述的指南并且进行了强制推送,接下来您可以审查我的PR,感谢您的审查

@thalissonvs
Copy link
Member

Hi @3-Tokisaki-Kurumi, I left some RC's that need to be resolved.

Also, it seems that your PR doesn’t reflect the new file structure introduced in the second version. If you need any help, I can implement some of the changes for you.

@3-Tokisaki-Kurumi
Copy link
Author

您好,感谢您的指正,我会根据您的建议修改,如果您能提供一些帮助,我将感激不尽,麻烦您了

Hello, thank you for your correction. If you could provide some help, I would be extremely grateful. Thank you very much

@3-Tokisaki-Kurumi
Copy link
Author

你好@3-Tokisaki-Kurumi,我留下了一些需要解决的RC。

另外,你的 PR 似乎不支持出第二版本中引入的新文件结构。如果你需要帮助,我可以帮助实现一些更改。

进行了一些变更,请您查看一下

Some changes have been made, please take a look

@thalissonvs
Copy link
Member

您好,感谢您的指正,我会根据您的建议修改,如果您能提供一些帮助,我将感激不尽,麻烦您了

Hello, thank you for your correction. If you could provide some help, I would be extremely grateful. Thank you very much

Sure, I'll help you on this weekend. Thanks for your efforts

@3-Tokisaki-Kurumi
Copy link
Author

3-Tokisaki-Kurumi commented Jun 22, 2025

您好,感谢您的建议,我会根据您的修改,如果能为您提供一些帮助,我将感激不尽,麻烦您了

您好,感谢您的指正。如果您能提供一些帮助,我将不胜感激。非常感谢

当然,这个周末我会帮你。谢谢你的努力

感谢您能提供帮助,另外我观察到最近的更新中对于当前的websockets库对新版本不兼容导致了报错已经得到了解决,还有我解决了现有的冲突

Thank you for providing assistance. Additionally, I have noticed that the recent update has resolved the issue of errors caused by the current websocket library being incompatible with the new version,And I resolved the existing conflict

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generate Browser Finger Print
2 participants