-
-
Notifications
You must be signed in to change notification settings - Fork 30
Add async waitFor() helper for DOM-based detections
#227
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
base: main
Are you sure you want to change the base?
Conversation
Implement the wait() async helper function that waits for a detection to return true by repeatedly checking it on each animation frame. This is useful for DOM-based detections that need to wait for elements to appear before the document is fully loaded. - Add wait() function that loops using requestAnimationFrame - Add comprehensive tests for the wait function - Update test infrastructure to support async detection functions - Add JSDoc documentation with usage examples Co-authored-by: fregante <1402241+fregante@users.noreply.github.com>
Co-authored-by: fregante <1402241+fregante@users.noreply.github.com>
Co-authored-by: fregante <1402241+fregante@users.noreply.github.com>
wait() helper for DOM-based detections
index.ts
Outdated
| * } | ||
| * ``` | ||
| */ | ||
| export async function wait(detection: () => boolean): Promise<boolean> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Export via
utilsonly. - Revert type changes (
detectionFn = detect as) in index.test.ts - Rename to
waitFor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in commit b177e73:
- Renamed
waittowaitFor - Moved to
utilsexport only (removed direct export) - Reverted type assertion changes in index.test.ts
fregante
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hopefully this works well 😍
- Renamed wait() to waitFor() as requested - Moved export to utils object instead of direct export - Reverted type assertion changes in index.test.ts - Updated README to show usage via utils.waitFor() - Updated JSDoc example to reflect new API Co-authored-by: fregante <1402241+fregante@users.noreply.github.com>
wait() helper for DOM-based detectionswaitFor() helper for DOM-based detections
DOM-based detections like
isOrganizationProfile()can fail if called before elements render. This adds an async wrapper to poll detections until they return true or the document completes loading.Implementation
utils.waitFor(detection): Polls detection function viarequestAnimationFrameuntil it returnstrueordocument.readyState === 'complete'Promise<boolean>utilsobject for better organizationUsage
Works with any detection function. Useful for features that initialize before page load completes.
Original prompt
elementReady-like helper for DOM detections #85💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.