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

Skip to content

fix: cnblogs detection logic#190

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

fix: cnblogs detection logic#190
timerring merged 1 commit intomainfrom
dev

Conversation

@timerring
Copy link
Member

Summary

This PR fixes the Cnblogs (博客园) platform detection logic by implementing a new API-based detection method.

Related Issue

N/A

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Performance improvement
  • Code refactoring
  • Other (please describe):

Changes Made

  • Removed cnblogs entry from LOGIN_CHECK_CONFIG in configs.js
  • Added new detectCnblogsUser function in platforms/cnblogs.js
  • Integrated detectCnblogsUser into PLATFORM_DETECTORS map in detect.js
  • Implemented MV3 service worker compatible cookie collection mechanism

Implementation Details

Key Changes:

  1. New Detection Strategy: Implemented a three-step detection process:

    • Collect cookies via chrome.cookies.getAll() API (MV3 compatible)
    • Fetch user info from account.cnblogs.com/user/userinfo with cookies attached manually
    • Extract username and avatar from API response
  2. Cookie Collection: Gather cookies from multiple domains (.cnblogs.com, www.cnblogs.com, account.cnblogs.com) and deduplicate them to ensure proper authentication.

  3. Avatar Handling: Process avatar URLs by:

    • Converting protocol-relative URLs to HTTPS
    • Converting Cnblogs-hosted avatars to Base64 format

Technical Notes:

  • Used chrome.cookies.getAll() instead of DOM-based detection to ensure compatibility with MV3 service workers
  • Implemented proper error handling with try-catch blocks
  • Returns structured response with loggedIn, username, and avatar fields
  • Falls back gracefully with { loggedIn: false } on any error

Testing

Testing Checklist

  • I have tested this code locally
  • All existing tests pass
  • I have added tests for new functionality
  • I have tested on the affected platform(s)
  • I have verified the changes work in the target browser(s)

Manual Testing Steps

  1. Install the extension with the updated code
  2. Navigate to cnblogs.com and log in
  3. Verify that the extension correctly detects the logged-in user
  4. Verify username and avatar are properly extracted and displayed

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 implementation replaces the previous Cnblogs detection logic with a more reliable API-based approach that is compatible with Chrome Manifest V3 service workers.

@timerring timerring self-assigned this Feb 14, 2026
@timerring timerring added the enhancement New feature or request label Feb 14, 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 560b33d into main Feb 14, 2026
@timerring timerring deleted the dev branch February 14, 2026 17:22
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