Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 15, 2025

This PR implements support for the onclick attribute on DOM Elements, enabling inline event handler assignments that are standard in web browsers.

What's Added

The implementation provides complete onclick attribute support including:

HTML Attribute Support:

<div onclick="console.log('clicked!')">Click me</div>

Implementation Details

Native Implementation (src/client/dom/)

  • Added onclick handler storage (onclick_handler_code_, has_onclick_function_, onclick_function_ref_) to Element class
  • Integrated onclick execution into the click event dispatch pipeline using DOMScriptingContext
  • Connected with browsing context for JavaScript execution framework
  • Complete V8 script compilation and execution for inline handler code

HTML Integration (src/client/html/)

  • Enhanced HTMLElement::attributeChangedCallback to handle onclick attribute changes
  • Seamless integration between HTML attributes and native onclick execution

Event Execution

  • Modified Element::simulateClick() to execute onclick handlers before normal event dispatch
  • Proper integration with the existing event system and bubbling behavior
  • Error handling for malformed handler code
  • Full JavaScript execution using browsing context's scripting infrastructure

Testing

Added comprehensive test file fixtures/html/element-onclick-test.html with visual test interface:

  • Interactive Test Buttons: Manual testing with visual feedback and animations
  • Automated Test Runner: Comprehensive test suite with real-time result display
  • Visual Results Panel: Color-coded pass/fail status with detailed logging
  • Test Statistics: Live tracking of passed/failed tests
  • On-Page Results: All test results displayed directly in the browser UI instead of console output

The test file validates:

  • HTML attribute parsing and execution
  • Programmatic click event triggering
  • Property assignment and getter functionality
  • Visual confirmation of onclick behavior

Web Compatibility

This implementation follows standard web behavior:

  • Onclick handlers execute before addEventListener handlers
  • Supports inline code strings with plans for function assignments
  • Proper execution context and error handling

The implementation works entirely at the native C++ level, providing onclick functionality without JavaScript property exposure. The JavaScript execution infrastructure uses the existing DOMScriptingContext for proper V8 integration.

Fixes #308.

Warning

registry.npmmirror.com

  • Triggering command: npm ci (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


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

Copilot AI and others added 2 commits September 15, 2025 07:06
Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
…t integration

Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
Copilot AI changed the title [WIP] Support Element.onclick property for inline event handlers Support Element.onclick property for inline event handlers Sep 15, 2025
Copilot AI requested a review from yorkie September 15, 2025 07:10
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to update the element binding

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Binding layer changes have been removed as requested. The onclick functionality now works entirely at the C++ level without JavaScript property exposure. (commit a5bd66b)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Please continue to complete all the TODOs in your code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All TODOs in element.cpp have been completed:

  • ✅ V8 execution implementation using DOMScriptingContext
  • ✅ Function reference storage in setOnClickHandlerFunction()
  • ✅ Click event handler integration via simulateClick()

The onclick functionality now properly compiles and executes JavaScript using the browsing context's scripting infrastructure. (commit a5bd66b)

…tion

Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Sep 15, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • registry.npmmirror.com
    • Triggering command: npm ci (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Support Element.onclick property for inline event handlers Support Element.onclick attribute for inline event handlers Sep 15, 2025
Copilot AI requested a review from yorkie September 15, 2025 07:44
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot You need to display the test results on the page, not just print them to the console.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test file updated to display results visually on the page instead of console output. The new interface includes:

  • Interactive Test Buttons: Manual testing with visual feedback and animations
  • Automated Test Runner: Comprehensive test suite with real-time result display
  • Visual Results Panel: Color-coded pass/fail status with detailed logging
  • Test Statistics: Live tracking of passed/failed tests

The page now provides a complete visual testing interface that shows all test results directly in the browser UI. (commit b7e9341)

Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
Copilot AI requested a review from yorkie September 16, 2025 09:43
@yorkie yorkie marked this pull request as ready for review September 16, 2025 10:01
@yorkie yorkie merged commit 83a628a into main Sep 16, 2025
2 checks passed
@yorkie yorkie deleted the copilot/fix-308 branch September 16, 2025 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Element.onclick property for inline event handlers

3 participants