Skip to content
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

Extension API to replace DOM elements with JSON data #245

Open
wants to merge 1 commit into
base: chromium
Choose a base branch
from

Conversation

Amit49
Copy link

@Amit49 Amit49 commented Feb 26, 2025

This patch introduces a new extension API that allows Wootz extensions to dynamically replace DOM elements using JSON-defined content. The implementation provides a secure and efficient way to modify webpage content through the extension system.

Key features:

  • New extension API method: chrome.wootz.replaceElement(selector, jsonData)
  • Support for complex nested elements and attributes
  • Efficient renderer-side DOM manipulation
  • Comprehensive JSON-to-HTML conversion

Technical implementation:

  • Adds new replace_element component with browser and renderer parts
  • Utilizes Mojo IPC for cross-process communication
  • Implements proper lifecycle management for frame-specific drivers
  • Includes comprehensive unit tests

The API accepts structured JSON data to define replacement elements, including:

  • Element type
  • Attributes (including styles)
  • Text content
  • Nested child elements

Example usage:
chrome.wootz.replaceElement("#target", {
element: "div",
attributes: { class: "new-container" },
children: [{ element: "p", content: "New content" }]
});

Example of extension usage: https://github.com/Amit49/Replace-Element-Extension-Example

Video of the feature:

2025-02-26-18-16-52.mp4

This patch introduces a new extension API that allows Wootz extensions to
dynamically replace DOM elements using JSON-defined content. The implementation
provides a secure and efficient way to modify webpage content through the
extension system.

Key features:
- New extension API method: chrome.wootz.replaceElement(selector, jsonData)
- Support for complex nested elements and attributes
- Efficient renderer-side DOM manipulation
- Comprehensive JSON-to-HTML conversion

Technical implementation:
- Adds new replace_element component with browser and renderer parts
- Utilizes Mojo IPC for cross-process communication
- Implements proper lifecycle management for frame-specific drivers
- Includes comprehensive unit tests

The API accepts structured JSON data to define replacement elements, including:
- Element type
- Attributes (including styles)
- Text content
- Nested child elements

Example usage:
chrome.wootz.replaceElement("#target", {
  element: "div",
  attributes: { class: "new-container" },
  children: [{ element: "p", content: "New content" }]
});

Signed-off-by: Amit Paul <amitpaul1304@gmail.com>
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.

1 participant