DevTools: Add monitoring on/off toggle by Makio64 · Pull Request #33760 · mrdoob/three.js · GitHub
Skip to content

DevTools: Add monitoring on/off toggle#33760

Draft
Makio64 wants to merge 7 commits into
mrdoob:devfrom
Makio64:fix/threejs-devtools
Draft

DevTools: Add monitoring on/off toggle#33760
Makio64 wants to merge 7 commits into
mrdoob:devfrom
Makio64:fix/threejs-devtools

Conversation

@Makio64

@Makio64 Makio64 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Related issue: -

Description

While the devtools panel is open it polls the inspected page every second, and each poll runs a full scene-graph traversal, reads clientWidth/clientHeight (forced layout) and posts whole scene batches across worlds — which can visibly hurt FPS on heavy scenes. Hovering tree items additionally clones objects/materials into the scene for highlighting.

This PR adds a monitoring On/Off toggle to the panel header:

  • Off makes the extension inert on the page: polling stops, the bridge gates request-state/details/highlight (sendState() early-returns), and any active highlight is removed so no wireframe gets stuck in the user's scene. The last snapshot stays visible (dimmed) in the panel.
  • On re-syncs the bridge, which clears its object-count cache and sends a fresh full state immediately (this also fixes a latent bug where reopening devtools could show an empty tree because the bridge's count cache suppressed the scene batch).
  • The choice is persisted in chrome.storage.local (shared across tabs and panels) and defaults to On (current behavior unchanged).
  • The toolbar icon’s right-click menu offers an "Monitor three.js scenes" checkbox too (works with or without an open panel), and the badge shows off while paused (the revision number is restored on re-enable). Left-clicking the icon keeps its existing scroll-to-canvas behavior. The state lives in chrome.storage.local and the background script syncs the menu checkbox, panel button, badge and page bridges from it — the badge is set centrally when a page registers, so it no longer goes stale.

Supporting changes this required:

  • New set-monitoring message forwarded panel → background → content script → bridge.
  • With polling stopped, nothing keeps the MV3 service worker alive, and its termination closes the panel port — previously a fatal event. The panel now reconnects on disconnect and re-asserts the monitoring state.
  • Top-level navigations are also detected via chrome.devtools.network.onNavigated, so panel state is cleared even when the committed message is dropped during a service worker restart; while off, iframe navigations no longer wipe the kept snapshot.
  • The construction-time observe path stays active while off (it is one-shot and cheap), so scenes/renderers created while paused appear instantly on re-enable.

The manifest version is intentionally left at 1.16.

🤖 Generated with Claude Code

Adds an Off mode to the devtools panel that makes the extension inert on
the inspected page: the 1s state polling stops (full scene traversal,
forced layout reads and postMessage batches with it) and hover
details/highlight messages are suppressed. The choice persists in
localStorage and defaults to On.

Since stopping the poll lets the MV3 service worker idle out and close
the panel port, the connection is now re-established on disconnect, and
top-level navigations are additionally detected via
chrome.devtools.network.onNavigated so state is cleared even when the
'committed' message is lost during a service worker restart.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Comment thread devtools/constants.js Fixed
@mrdoob

mrdoob commented Jun 10, 2026

Copy link
Copy Markdown
Owner

While the panel is open, clicking the extension icon toggles monitoring
on/off and the badge shows 'off' while paused (the revision is restored
on re-enable). Without an open panel the icon click keeps its previous
scroll-to-canvas behavior.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Comment thread devtools/constants.js Fixed
Comment thread devtools/constants.js Fixed
Makio64 and others added 2 commits June 10, 2026 07:38
Right-clicking the extension icon now offers a 'Toggle monitoring' menu
option while the panel is open; left-clicking the icon keeps its
scroll-to-canvas behavior.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Right-clicking the extension icon now offers an 'Enable monitoring'
checkbox; left-click keeps its scroll-to-canvas behavior. The state
moved from panel localStorage to chrome.storage.local so the background
script owns it: it sets the badge directly when a page registers, keeps
the menu checkbox, panel button, badge and page bridges in sync, and
remembers each tab's revision in chrome.storage.session - fixing the
badge sometimes showing a stale off/version state.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Comment thread devtools/constants.js
var MESSAGE_UNHIGHLIGHT_OBJECT = 'unhighlight-object';
var MESSAGE_REGISTER = 'register';
var MESSAGE_COMMITTED = 'committed';
var MESSAGE_SET_MONITORING = 'set-monitoring';
Comment thread devtools/constants.js
var MESSAGE_SET_MONITORING = 'set-monitoring';

// chrome.storage.local keys
var STORAGE_KEY_MONITORING = 'monitoring-enabled';
Makio64 and others added 2 commits June 10, 2026 11:17
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Makio64

Makio64 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

New option on right click:
Screenshot 2026-06-10 at 17 47 31

when off
Screenshot 2026-06-10 at 17 46 13
when on ( default on, setting is save by page )

Screenshot 2026-06-10 at 17 46 05

@mrdoob

mrdoob commented Jun 11, 2026

Copy link
Copy Markdown
Owner

UX looks good to me.

Code wise feels like a lot of code for such a small feature. What /effort are you using?

@Makio64

Makio64 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

@mrdoob

UX looks good to me.

Code wise feels like a lot of code for such a small feature. What /effort are you using?

It was Claude max, but the extra code with the worker was a confirmation due to a bug i met. It's now fix ( fable 5 xhigh )

@Mugen87

Mugen87 commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Similar to #31015 (comment), do we really need this? You can enable/disable the extension so easily in Chrome.

Apart from the large code base change, this feature requires two new permissions which is unfortunate.

@mrdoob

mrdoob commented Jun 12, 2026

Copy link
Copy Markdown
Owner

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.

4 participants