Implement Web Notification API in src/client #395
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements the Web Notification API for JSAR Runtime, enabling web applications to display system notifications following the W3C Notification specification.
Implementation Overview
The implementation provides a complete, spec-compliant foundation for the Notification API with clear extension points for platform-specific notification displays.
Core Components
C++ Implementation (
src/client/dom/notification.hpp/.cpp):Notificationclass extendingDOMEventTargetfor proper event handlingtitle,body,icon,tag,badge,sound,dir,lang,renotify,requireInteraction,silentNotification.permissionandNotification.requestPermission()close()for programmatic dismissalJavaScript Bindings (
src/client/script_bindings/notification.hpp/.cpp):ObjectWrap-based bindings following JSAR's established patternsonshow,onclick,onclose,onerrorGlobal Registration (
src/client/script_bindings/binding.cpp):JavaScript API Usage
Testing
tests/fixtures/notification-example.js) demonstrating all API featuresDocumentation
docs/api/notification-api.md): Complete documentation with usage examplesdocs/implementation/notification-api-summary.md): Detailed architecture and design decisionsCurrent Status
✅ Implemented
🚧 Future Work (Documented with TODOs)
requestPermission(): Currently synchronous stubDesign Decisions
Stub Permission Model: Auto-grants permission to enable immediate development and testing. Platform-specific permission dialogs can be added through marked integration points.
EventTarget Inheritance: Notification extends DOMEventTarget, providing a solid foundation for future event dispatching implementation.
Clear Extension Points: Platform-specific implementation points are marked with TODO comments in the code and documented in the implementation summary.
Spec Compliance: Follows W3C Notification API specification and MDN patterns, with structure inspired by Chromium's implementation.
References
Fixes #[issue-number]
Original prompt
Fixes #394
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.