Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: huaweidev cors detection#182

Merged
timerring merged 1 commit intomainfrom
dev
Feb 9, 2026
Merged

fix: huaweidev cors detection#182
timerring merged 1 commit intomainfrom
dev

Conversation

@timerring
Copy link
Member

Summary / 概述

Fixed Huawei Developer platform user detection by replacing CORS-blocked API approach with DOM extraction strategy. The previous method failed due to CORS policy restrictions when calling the delegate API.

Related Issue / 关联 Issue

N/A

Type of Change / 更改类型

  • Bug fix / 修复 Bug (non-breaking change that fixes an issue / 修复问题的非破坏性更改)

Changes Made / 更改内容

  • Replaced CSRF token-based API call with DOM extraction approach
  • Updated manifest.json host permissions to include https://*.huawei.com/* and https://*.hicloud.com/*
  • Removed dependency on developer_userinfo cookie parsing for CSRF token
  • Implemented script injection to extract avatar and username from rendered DOM

Implementation Details / 实现细节

Key Changes / 主要更改:

  • Changed detection strategy from API-based to DOM-based extraction
  • Added chrome.scripting.executeScript to inject code into open Huawei Developer tabs
  • Extract avatar from img#avatar-img element
  • Extract username from .avatarArea spans with filtering logic to skip non-username text
  • Convert avatar URL to base64 using convertAvatarToBase64 utility to bypass CORS/ORB restrictions

Technical Notes / 技术说明:

  • The original approach failed because the delegate API (https://svc-drcn.developer.huawei.com/codeserver/Common/v1/delegate) blocks requests with CORS policy
  • New approach requires an open developer.huawei.com tab to extract DOM elements
  • Avatar conversion to base64 is necessary to avoid Opaque Response Blocking (ORB)
  • Username extraction includes filtering logic to skip menu items and metadata (verified badge, level, post counts, etc.)

Testing / 测试

Testing Checklist / 测试清单

  • I have tested this code locally / 我已在本地测试此代码
  • All existing tests pass / 所有现有测试通过
  • I have tested on the affected platform(s) / 我已在受影响的平台上测试
  • I have verified the changes work in the target browser(s) / 我已验证更改在目标浏览器中有效

Manual Testing Steps / 手动测试步骤

  1. Open Huawei Developer website (https://developer.huawei.com) and log in
  2. Trigger the detection function
  3. Verify that username and avatar are correctly extracted
  4. Confirm avatar is properly converted to base64 format

Screenshots/Videos / 截图/视频

N/A

Reviewer Checklist / 审阅者清单

  • Code follows the project's style guidelines / 代码遵循项目的风格指南
  • Changes are well-documented / 更改有良好的文档说明
  • No breaking changes or clearly documented if present / 无破坏性更改,或已清楚记录
  • Security implications have been considered / 已考虑安全影响
  • Performance impact has been evaluated / 已评估性能影响
  • All discussions have been resolved / 所有讨论已解决

Additional Notes / 补充说明

This change requires users to have an open Huawei Developer tab for detection to work. If no tab is open, the detection will return logged-in status with empty username and avatar fields.

@timerring timerring self-assigned this Feb 9, 2026
@timerring timerring added the enhancement New feature or request label Feb 9, 2026
Copy link
Member Author

@timerring timerring left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@timerring timerring merged commit 4b038b2 into main Feb 9, 2026
@timerring timerring deleted the dev branch February 9, 2026 09:01
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.

1 participant