#55739: fix: set up DevTools extension API before the extension page runs
Description of Change
Fixes #55394.
chrome extensions > devtools extensions > loads a devtools extension flaked on linux-x64 because InspectableWebContents::DidFinishNavigation() injected the DevTools extension API into the extension frame with ExecuteJavaScriptForTests(). That races the extension page's own scripts; when the page wins, chrome.devtools is undefined (Cannot read properties of undefined (reading 'panels')), the devtools_page never creates its panel, and the test times out.
This moves the setup to ReadyToCommitNavigation() and hands the script to Blink via content::DevToolsFrontendHost::SetupExtensionsAPI(), matching Chrome's DevToolsUIBindings. Blink then runs it from DevToolsFrontendImpl::DidClearWindowObject(), before any page script. (The old comment said SetupExtensionsAPI seemed to be a no-op; that was because it was being called after commit, once the window object had already been cleared.) The stale "var chrome" rewrite is dropped too: the frontend now emits const chrome = window.chrome || {}, so it no longer matched anything.
Spec changes:
spec/extensions.spec.tsnow runs with{ retry: 0 }.- The devtools extension test awaits
loadExtension()before opening DevTools.
Verified locally on macOS: all extensions.spec.ts tests pass on the first attempt with retries disabled, and loads a devtools extension passed 15/15 isolated runs.
Checklist
- PR description included
-
npm testpasses - tests are changed or added
- PR release notes describe the change in a way relevant to app developers, and are capitalized, punctuated, and past tense.
🤖 Generated with Claude Code
Notes: Fixed a race where a DevTools extension's devtools_page could run before chrome.devtools was available.
Backports
Semver Impact
Semantic Versioning helps users understand the impact of updates:
- Major (X.y.z): Breaking changes that may require code modifications
- Minor (x.Y.z): New features that maintain backward compatibility
- Patch (x.y.Z): Bug fixes that don't change the API
- None: Changes that don't affect using facing parts of Electron