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

Skip to content

fix: oschina detection#189

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

fix: oschina detection#189
timerring merged 1 commit intomainfrom
dev

Conversation

@timerring
Copy link
Member

Summary

Fixed OSChina platform detection to work with MV3 service workers by switching from HTML parsing to cookie-based authentication check with API fallback.

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

  • Replaced HTML parsing approach with cookie-based authentication detection
  • Implemented chrome.cookies API for MV3 service worker compatibility
  • Added API endpoint call to fetch user information (username and avatar)
  • Simplified detection logic by removing complex regex patterns
  • Improved error handling with graceful fallback

Implementation Details

Key Changes:

  • Changed login detection from HTML parsing to checking oscid cookie existence
  • Migrated from fetch with HTML parsing to chrome.cookies.get API
  • Added /oschinapi/user/myDetails API call for username and avatar retrieval
  • Implemented comprehensive cookie collection from multiple domains (.oschina.net, www.oschina.net, apiv1.oschina.net)
  • Removed deprecated profile page scraping logic

Technical Notes:

  • MV3 service workers cannot use document or DOM APIs, requiring cookie-based approach
  • Cookie-based detection is more reliable and less fragile than HTML parsing
  • API approach provides structured data instead of regex extraction
  • Falls back gracefully if API call fails, still detecting login state via cookie

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. Log in to OSChina website
  2. Verify the extension detects the logged-in state via oscid cookie
  3. Confirm username and avatar are correctly fetched from API
  4. Test with logged-out state to ensure proper detection of non-authenticated users

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 fix addresses compatibility issues with Manifest V3 service workers where DOM-based operations are not available. The cookie-based approach is more maintainable and less prone to breakage from UI changes on OSChina's website.

@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.

LGMT

@timerring timerring merged commit cf426af into main Feb 14, 2026
@timerring timerring deleted the dev branch February 14, 2026 16:58
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