Skip to content

Added new DevTools #30870

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

Draft
wants to merge 55 commits into
base: dev
Choose a base branch
from
Draft

Added new DevTools #30870

wants to merge 55 commits into from

Conversation

mrdoob
Copy link
Owner

@mrdoob mrdoob commented Apr 5, 2025

Description

Started a new and simpler Three.js DevTools.

Screenshot 2025-04-05 at 10 25 20

@mrdoob mrdoob added this to the r176 milestone Apr 5, 2025
@mrdoob mrdoob requested a review from Copilot April 5, 2025 02:40
Copilot

This comment was marked as outdated.

mrdoob and others added 3 commits April 5, 2025 11:45
… local variable

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@mrdoob mrdoob modified the milestones: r176, r177 Apr 24, 2025
@mrdoob
Copy link
Owner Author

mrdoob commented May 12, 2025

We now show the three.js version detected in the icon badge:

Screenshot 2025-05-12 at 20 51 53

@mrdoob mrdoob modified the milestones: r177, r178 May 30, 2025
@mrdoob mrdoob modified the milestones: r178, r179 Jun 30, 2025
@mrdoob
Copy link
Owner Author

mrdoob commented Jul 14, 2025

We can now show the object transforms.

Screen.Recording.2025-07-13.at.5.44.41.PM_.mov

@mrdoob mrdoob requested a review from Copilot July 14, 2025 00:28
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new, simplified Chrome DevTools extension for inspecting Three.js scenes and renderers, including panel UI, messaging infrastructure, and documentation.

  • Added panel UI (panel.js, panel.html, panel.css) for rendering scene and renderer details
  • Implemented messaging flow (devtools.js, content-script.js, bridge.js, background.js) between page, background, and panel
  • Included extension manifest and README for setup and architecture overview

Reviewed Changes

Copilot reviewed 10 out of 13 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
devtools/panel/panel.js UI logic for scene tree, renderer sections, and floating panel
devtools/panel/panel.html HTML structure for DevTools panel
devtools/panel/panel.css Styling for panel components and floating details
devtools/manifest.json Extension metadata, permissions, and devtools page configuration
devtools/index.html Loader page for DevTools panel
devtools/devtools.js Registers the “Three.js” tab in Chrome DevTools
devtools/content-script.js Injects bridge script and relays messages
devtools/bridge.js In-page bridge interacting with Three.js and dispatching events
devtools/background.js Manages port connections and message forwarding
devtools/README.md Installation and architecture documentation
Comments suppressed due to low confidence (1)

devtools/panel/panel.js:4

  • The utility function getObjectIcon has no associated tests. Adding unit tests to cover each icon mapping will help prevent regressions as new object types are added.
function getObjectIcon(obj) {

Comment on lines +86 to +102
const intervalId = setInterval( () => {

backgroundPageConnection.postMessage( {
name: 'request-state',
tabId: chrome.devtools.inspectedWindow.tabId
} );

}, 1000 );

backgroundPageConnection.onDisconnect.addListener( () => {

console.log( 'Panel: Connection to background page lost' );
clearInterval( intervalId );
clearState();

} );

Copy link
Preview

Copilot AI Jul 14, 2025

Choose a reason for hiding this comment

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

Polling the entire state every second can be inefficient and may cause unnecessary UI updates. Consider switching to an event-driven update model where the bridge pushes updates only when data changes.

Suggested change
const intervalId = setInterval( () => {
backgroundPageConnection.postMessage( {
name: 'request-state',
tabId: chrome.devtools.inspectedWindow.tabId
} );
}, 1000 );
backgroundPageConnection.onDisconnect.addListener( () => {
console.log( 'Panel: Connection to background page lost' );
clearInterval( intervalId );
clearState();
} );
backgroundPageConnection.onMessage.addListener((message) => {
if (message.name === 'state-update') {
updateState(message.state);
}
});
backgroundPageConnection.onDisconnect.addListener(() => {
console.log('Panel: Connection to background page lost');
clearState();
});

Copilot uses AI. Check for mistakes.

Comment on lines +295 to +297
summaryElem.innerHTML = `<span class="icon toggle-icon"></span>
<span class="label">${displayName}</span>
<span class="type">${obj.type}</span>`;
Copy link
Preview

Copilot AI Jul 14, 2025

Choose a reason for hiding this comment

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

Using innerHTML with interpolated content can introduce XSS risks if any data is unexpected. Prefer building DOM nodes via createElement and textContent, or sanitize the inserted HTML.

Suggested change
summaryElem.innerHTML = `<span class="icon toggle-icon"></span>
<span class="label">${displayName}</span>
<span class="type">${obj.type}</span>`;
const toggleIconSpan = document.createElement('span');
toggleIconSpan.className = 'icon toggle-icon';
const labelSpan = document.createElement('span');
labelSpan.className = 'label';
labelSpan.textContent = `${obj.type} `;
const objectDetailsSpan = document.createElement('span');
objectDetailsSpan.className = 'object-details';
objectDetailsSpan.textContent = details.join(' ・ ');
labelSpan.appendChild(objectDetailsSpan);
const typeSpan = document.createElement('span');
typeSpan.className = 'type';
typeSpan.textContent = obj.type;
summaryElem.appendChild(toggleIconSpan);
summaryElem.appendChild(labelSpan);
summaryElem.appendChild(typeSpan);

Copilot uses AI. Check for mistakes.

row.style.marginBottom = '2px';

// Pad label to ensure consistent alignment
const paddedLabel = label.padEnd(16, ' '); // Pad to 16 characters
Copy link
Preview

Copilot AI Jul 14, 2025

Choose a reason for hiding this comment

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

[nitpick] The padding length 16 is a magic number. Extract it into a named constant (e.g., LABEL_PAD_LENGTH) so its purpose is clear and maintainable.

Suggested change
const paddedLabel = label.padEnd(16, ' '); // Pad to 16 characters
const paddedLabel = label.padEnd(LABEL_PAD_LENGTH, ' '); // Pad to LABEL_PAD_LENGTH characters

Copilot uses AI. Check for mistakes.

let displayName = obj.name || obj.type;

// Default rendering for other object types
const elem = document.createElement( 'div' );
Copy link
Preview

Copilot AI Jul 14, 2025

Choose a reason for hiding this comment

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

These tree-item divs represent interactive nodes but lack ARIA roles for screen readers. Consider using role="treeitem" and aria-expanded attributes to improve accessibility.

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants