Skip to content

Expose URL Metric to Chrome DevTools for agents#2571

Open
faisalahammad wants to merge 1 commit into
WordPress:trunkfrom
faisalahammad:fix/2553-devtools-discovery
Open

Expose URL Metric to Chrome DevTools for agents#2571
faisalahammad wants to merge 1 commit into
WordPress:trunkfrom
faisalahammad:fix/2553-devtools-discovery

Conversation

@faisalahammad

Copy link
Copy Markdown

Summary

Fixes #2553

Adds a small Optimization Detective extension module that registers with Chrome's new DevTools for agents third-party tools API. It exposes two read-only tools, get_od_url_metric and get_od_element_data, so an AI coding agent can inspect the URL Metric being collected for the current page load while debugging performance. Only active when WP_DEBUG is enabled.

Relevant technical choices

  • Shipped as a new extension module (devtools-discovery.js), same mechanism Embed Optimizer and Image Prioritizer already use via the od_extension_module_urls filter. No changes to core detect.js.
  • The module only calls the getRootData() / getElementData() functions that are already handed to every extension's initialize(), so there's no new state tracking.
  • The filter is only added when WP_DEBUG is true, since this is a debugging feature and should cost nothing in production (no extra listener, no extra data collection).
  • Added PHPUnit coverage for the new filter callback and the conditional hook registration, plus a short note in the extension docs.

How to test

  1. Build the plugin and run a local WP site with WP_DEBUG set to true.
  2. Configure the Chrome DevTools MCP server with --categoryExperimentalThirdParty=true.
  3. Ask an agent to list third-party developer tools on a page. You should see an "Optimization Detective" group with get_od_url_metric and get_od_element_data.
  4. Invoke get_od_url_metric, confirm it returns the current URL Metric (viewport + tracked elements).
  5. Set WP_DEBUG to false, reload, confirm the tool group no longer appears.

Also ran composer test:optimization-detective, composer lint:optimization-detective, npm run phpstan, and npm run tsc locally, all passing.

…r agents

- Add devtools-discovery.js extension module registering two read-only
  tools (get_od_url_metric, get_od_element_data) via the
  devtoolstooldiscovery event
- Register it through the existing od_extension_module_urls filter,
  gated on WP_DEBUG
- Add tests and a short docs note

Lets an AI coding agent inspect the URL Metric being collected for
the current page load while debugging performance, via Chrome
DevTools for agents third-party tools API.

Fixes WordPress#2553
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: faisalahammad <faisalahammad@git.wordpress.org>
Co-authored-by: westonruter <westonruter@git.wordpress.org>
Co-authored-by: swissspidy <swissspidy@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions github-actions Bot added the [Plugin] Optimization Detective Issues for the Optimization Detective plugin label Jul 5, 2026
@codecov

codecov Bot commented Jul 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.37%. Comparing base (8d70987) to head (703d128).

Additional details and impacted files
@@            Coverage Diff             @@
##            trunk    #2571      +/-   ##
==========================================
+ Coverage   70.35%   70.37%   +0.02%     
==========================================
  Files          91       91              
  Lines        7867     7873       +6     
==========================================
+ Hits         5535     5541       +6     
  Misses       2332     2332              
Flag Coverage Δ
multisite 70.37% <100.00%> (+0.02%) ⬆️
single 35.14% <0.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Plugin] Optimization Detective Issues for the Optimization Detective plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DevTools Discovery API integration

1 participant