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 6 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

新内置一个指纹伪装功能
Add fingerprint camouflage
New built-in fingerprint camouflage function

Pull Request: 添加浏览器指纹伪装功能

#Pull Request: 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 can effectively avoid being detected as an automated tool by websites, enhance privacy protection, and improve the success rate of web crawlers.

实现了以下核心功能:
The following core functions have been implemented:

  • 完整的指纹生成系统,包括UserAgent、WebGL、Canvas、Audio等多维度伪装
    -A complete fingerprint generation system, including UserAgent, WebGL, Canvas, Audio, and other multi-dimensional disguises
  • 一键启用设计,只需设置enable_fingerprint_spoofing=True参数
    -One click enable design, just set the parameter 'enable_fingerprint_stpoofing=True'
  • 全局指纹管理器单例,方便在不同模块间共享指纹信息
    -Global fingerprint manager singleton, convenient for sharing fingerprint information between different modules
  • 自动注入JavaScript保护代码,深度伪装浏览器特征
    -Automatically inject JavaScript protection code, deeply disguise browser features

相关问题

##Related issues

  • 解决了自动化浏览中被反爬系统识别的问题
    -Solved the problem of being recognized by anti crawling systems in automated browsing
  • 增强了用户隐私保护能力
    -Enhanced user privacy protection capability
  • 提高了在防指纹网站上的操作稳定性
    -Improved operational stability on anti fingerprint websites

变更类型

##Change type

  • 新功能(增加功能且向后兼容)
    -[x] New features (added functionality and backward compatibility)
  • Bug修复(向后兼容的问题修复)
    -[] Bug fixes (fixes for backward compatibility issues)
  • 破坏性变更(会导致现有功能不可用)
    -[] Destructive changes (causing existing functionality to be unavailable)
  • 文档更新
    -[x] Document update
  • 重构(无功能变化)
    -Refactoring (no functional changes)
  • 性能改进
    -[] Performance improvement
  • 测试(添加缺失的测试或修正现有测试)
    -[x] Testing (adding missing tests or correcting existing tests)
  • 构建或CI/CD相关变更
    -[x] Build or CI/CD related changes

测试方法

##Testing method
该功能通过以下方式进行了测试:
This feature was tested through the following methods:

  1. 功能测试:在多个浏览器实例上验证指纹唯一性
  2. Functional testing: Verify fingerprint uniqueness on multiple browser instances
```python
from pydoll.browser.chrome import Chrome
from pydoll.browser.chrome import Chrome
from pydoll.browser.options import Options
from pydoll.browser.options import Options


# 创建Chrome选项
#Create Chrome Options
options = Options()
options = Options()


# 只需添加这一行就能启用指纹伪装
#Just add this line to enable fingerprint camouflage
browser = Chrome(options=options, enable_fingerprint_spoofing=True)
browser = Chrome(options=options, enable_fingerprint_spoofing=True)


# 正常使用浏览器,自动应用指纹伪装
#Normal use of browser, automatic application of fingerprint camouflage
await browser.start()
await browser.start()
page = await browser.get_page()
page = await browser.get_page()
await page.go_to("https://fingerprintjs.github.io/fingerprintjs/")
await page.go_to(" https://fingerprintjs.github.io/fingerprintjs/ ")


2. 多实例测试:确保不同浏览器实例生成不同的指纹
2. Multi instance testing: Ensure that different browser instances generate different fingerprints
3. 抵抗检测测试:在常见的指纹检测网站上进行测试
3. Resistance testing: Conduct testing on common fingerprint detection websites


## 测试清单
##Test Checklist
- [x] 单元测试已添加/更新
-[x] Unit tests have been added/updated
- [x] 集成测试已添加/更新
-[x] Integration testing has been added/updated
- [x] 所有现有测试通过
-[x] All existing tests passed


## 技术实现概述
##Overview of Technical Implementation
本功能主要通过以下三个方面实现:
This function is mainly implemented through the following three aspects:


1. **指纹生成**:使用`FingerprintGenerator`类生成随机的、真实的指纹数据,包括浏览器、操作系统、显卡等多维度信息
1. * * Fingerprint Generation * *: Use the 'FingerprintGenerator' class to generate random, authentic fingerprint data, including multi-dimensional information such as browsers, operating systems, graphics cards, etc


2. **命令行参数**:通过`get_fingerprint_arguments`方法为浏览器启动添加必要的命令行参数,如语言、分辨率等
2. * * Command line parameters * *: Add necessary command line parameters such as language, resolution, etc. to the browser startup through the ` get_fingerprint_arguments ` method


3. **JavaScript注入**:通过`get_fingerprint_js`方法生成JavaScript代码,注入到页面中覆盖各种指纹相关API,包括:
3. * * JavaScript injection * *: Generate JavaScript code through the ` get_fingerprint_js ` method and inject it into the page to cover various fingerprint related APIs, including:
- Navigator属性(userAgent, languages, platform等)
-Navigator properties (userAgent, languages, platform, etc.)
- WebGL参数(vendor, renderer等)
-WebGL parameters (vendor, renderer, etc.)
- Canvas和Audio指纹保护
-Canvas and Audio fingerprint protection
- 禁用自动化检测标记
-Disable automated detection tagging


## 使用示例
##Example usage
```python
```python
# 最简单的一键启用方式
#The simplest one click activation method
browser = Chrome(enable_fingerprint_spoofing=True)
browser = Chrome(enable_fingerprint_spoofing=True)


# 高级用法:手动控制指纹
#Advanced usage: Manual control of fingerprints
from pydoll.browser import FINGERPRINT_MANAGER
from pydoll.browser import FINGERPRINT_MANAGER


# 生成新指纹
#Generate new fingerprints
fingerprint = FINGERPRINT_MANAGER.generate_new_fingerprint('chrome')
fingerprint = FINGERPRINT_MANAGER.generate_new_fingerprint('chrome')
print(f"指纹ID: {fingerprint['id']}")
Print (f "Fingerprint ID: {fingerprint ['id ']}")
print(f"用户代理: {fingerprint['user_agent']}")
Print (f "User Agent: {fingerprint ['user_agent ']}")


# 获取启动参数
#Get startup parameters
arguments = FINGERPRINT_MANAGER.get_fingerprint_arguments()
arguments = FINGERPRINT_MANAGER.get_fingerprint_arguments()


# 获取注入代码
#Obtain injection code
js_code = FINGERPRINT_MANAGER.get_fingerprint_js()
js_code = FINGERPRINT_MANAGER.get_fingerprint_js()


## 下一步计划
##Next plan
- 增加更多浏览器类型支持
-Add support for more browser types
- 添加指纹持久化存储
-Add fingerprint persistent storage
- 进一步增强对高级指纹检测的抵抗能力
-Further enhance the resistance to advanced fingerprint detection

Copy link

codecov bot commented May 10, 2025

@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

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

Successfully merging this pull request may close these issues.

2 participants