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

Skip to content

refactor: huaweicloud logic#192

Merged
timerring merged 2 commits intomainfrom
dev
Feb 15, 2026
Merged

refactor: huaweicloud logic#192
timerring merged 2 commits intomainfrom
dev

Conversation

@timerring
Copy link
Member

Summary

Refactored HuaweiCloud platform logic to improve reliability and user experience:

  • Implemented 7-day local storage cache for user info

In our initial implementation of HuaweiCloud, we used a similar approach to Volcengine by modifying the Origin request header through declarativeNetRequest.

However, we found that the platform detection often failed because there was a time gap between when the detection ran and when the page fully loaded. Therefore, we ultimately reverted to a storage-based approach that caches user info locally and retrieves it from the cache.

  • Enhanced content synchronization with MutationObserver-based iframe detection
  • Added message event confirmation mechanism for content filling
  • Simplified detection logic by removing complex cookie handling

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

  • Implemented chrome.storage.local cache for HuaweiCloud user info with 7-day TTL
  • Added automatic user info caching in content script when visiting huaweicloud.com
  • Refactored user detection logic to prioritize cache, then executeScript on open tabs
  • Enhanced content filling with MutationObserver to wait for iframe readiness
  • Implemented retry mechanism (6 attempts) with message event confirmation
  • Removed complex csrf cookie handling and simplified authentication flow
  • Separated title and content filling into independent operations

Implementation Details

Key Changes:

  • User Detection: Cache-first strategy (check cache → executeScript on tab → cookie fallback)
  • Content Sync: waitForEditorReady() uses MutationObserver to detect iframe insertion
  • Content Confirmation: setContentWithConfirm() listens for 'setMdDataSucc' message event
  • Retry Logic: 6 retries with 2s intervals, fallback to direct postMessage if all retries fail

Technical Notes:

  • Content script auto-fetches user info after 3s delay (for SSO login)
  • MutationObserver watches document.body with { childList: true, subtree: true }
  • Message event listener handles both 'setMdDataSucc' and 'mdContent' actions
  • Timeout fallback (15s for iframe wait, 3s per content fill attempt)
  • All API calls use credentials: 'include' for cookie-based auth

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. Visit bbs.huaweicloud.com and log in
  2. Open COSE extension popup
  3. Verify user info is detected and cached
  4. Create/edit a blog post
  5. Sync content from COSE to HuaweiCloud blog
  6. Verify title and markdown content are filled correctly
  7. Close and reopen browser, verify cache is used (check console logs)
  8. Wait 7 days or manually clear cache, verify re-detection works

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 refactoring significantly improves the HuaweiCloud integration reliability by:

  1. Reducing repeated API calls through caching
  2. Eliminating race conditions with MutationObserver-based iframe detection
  3. Providing robust retry mechanism for content synchronization
  4. Simplifying the authentication flow by removing complex cookie manipulation

@timerring timerring self-assigned this Feb 15, 2026
@timerring timerring added the enhancement New feature or request label Feb 15, 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 48a604f into main Feb 15, 2026
@timerring timerring deleted the dev branch February 15, 2026 10:06
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