Skip to content

fix: toggle devtools menu item for BaseWindow#49356

Merged
dsanders11 merged 7 commits into
electron:mainfrom
KanishkRanjan:feat/web-contents-dev-tools
Jun 5, 2026
Merged

fix: toggle devtools menu item for BaseWindow#49356
dsanders11 merged 7 commits into
electron:mainfrom
KanishkRanjan:feat/web-contents-dev-tools

Conversation

@KanishkRanjan

@KanishkRanjan KanishkRanjan commented Jan 11, 2026

Copy link
Copy Markdown
Contributor

Description of Change

Fixes: #45821, #45386

This PR fixes a "JavaScript error in main process" that occurs when a developer attempts to trigger the toggleDevTools when running BaseWindow. Unlike BrowserWindow, BaseWindow have multiple WebContents which cause it to fail. This changes the logic to target the currently focused WebContents regardless of the window.

Root Cause

The pervious implementation of the toggledevtools menu role used getOwnerBrowserWindow() which returns {} when window is hosted within aBaseWindow and later when function call toggleDevTools was made it causes JS error .

Checklist

Release Notes

Notes: Fixed an issue where the "Toggle Developer Tools" menu item failed to function correctly with BaseWindow.

@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Jan 11, 2026
@codebytere codebytere requested a review from nikwen January 12, 2026 10:31

@nikwen nikwen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for working on this!

Comment thread lib/browser/api/menu-item-roles.ts Outdated
Comment thread shell/browser/api/electron_api_web_contents.cc Outdated
@KanishkRanjan KanishkRanjan changed the title feat: Developers tools for BaseWindow feat: Developers tools for BaseWindow Jan 13, 2026
@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Jan 18, 2026
@KanishkRanjan KanishkRanjan marked this pull request as draft February 4, 2026 18:33
@nikwen nikwen added the wip ⚒ label Mar 12, 2026
@KanishkRanjan KanishkRanjan force-pushed the feat/web-contents-dev-tools branch from 764c670 to cb36f07 Compare March 15, 2026 19:21
@KanishkRanjan

KanishkRanjan commented Mar 16, 2026

Copy link
Copy Markdown
Contributor Author

The current commit doesn't address the review so please don't view it.

@KanishkRanjan KanishkRanjan marked this pull request as ready for review March 16, 2026 09:00
@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Mar 16, 2026
@nikwen nikwen changed the title feat: Developers tools for BaseWindow feat: fix toggle devtools menu item for BaseWindow Mar 17, 2026
@nikwen nikwen changed the title feat: fix toggle devtools menu item for BaseWindow fix: toggle devtools menu item for BaseWindow Mar 17, 2026
@nikwen nikwen added the semver/patch backwards-compatible bug fixes label Mar 17, 2026
@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Mar 17, 2026
@nikwen

nikwen commented Mar 17, 2026

Copy link
Copy Markdown
Member

Is it easy to add a test that sending the keyboard shortcut to the application toggles the devtools?

I remember @codebytere mentioning AppleScript as a potential way to do it in a similar context.

@KanishkRanjan

Copy link
Copy Markdown
Contributor Author

@nikwen what can I do next ?

Comment thread shell/browser/api/electron_api_web_contents.cc Outdated
@KanishkRanjan KanishkRanjan force-pushed the feat/web-contents-dev-tools branch from 76cf541 to 91c7665 Compare May 1, 2026 21:32
@KanishkRanjan

Copy link
Copy Markdown
Contributor Author

discloser: test was written by claude. I asked for suggestion on writing test and found it good enough.

@KanishkRanjan KanishkRanjan requested a review from nikwen May 1, 2026 21:36
@nikwen nikwen removed the wip ⚒ label May 20, 2026

@nikwen nikwen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for working on this! We're almost there. 🙂

Comment thread spec/api-menu-item-spec.ts Outdated
Comment thread spec/api-menu-item-spec.ts
Comment thread lib/browser/api/menu-item-roles.ts Outdated

@nikwen nikwen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the changes!

Comment thread spec/api-menu-item-spec.ts Outdated
Comment thread spec/api-menu-item-spec.ts
@KanishkRanjan KanishkRanjan requested a review from nikwen May 28, 2026 09:27

@nikwen nikwen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you! Looks great.

@nikwen nikwen added target/41-x-y PR should also be added to the "41-x-y" branch. target/42-x-y PR should also be added to the "42-x-y" branch. target/43-x-y PR should also be added to the "43-x-y" branch. labels Jun 1, 2026
@KanishkRanjan KanishkRanjan force-pushed the feat/web-contents-dev-tools branch from e3740e7 to 149b257 Compare June 2, 2026 11:07
@KanishkRanjan KanishkRanjan marked this pull request as draft June 2, 2026 11:09
@nikwen nikwen marked this pull request as ready for review June 3, 2026 09:43
@github-actions

This comment was marked as outdated.

@github-actions github-actions Bot closed this Jun 3, 2026
@nikwen nikwen reopened this Jun 3, 2026
@KanishkRanjan

Copy link
Copy Markdown
Contributor Author

Hey @ckerr , Can you please approve this PR 🙂 ?

@dsanders11 dsanders11 merged commit e8eeeb0 into electron:main Jun 5, 2026
205 of 223 checks passed
@release-clerk

release-clerk Bot commented Jun 5, 2026

Copy link
Copy Markdown

Release Notes Persisted

Fixed an issue where the "Toggle Developer Tools" menu item failed to function correctly with BaseWindow.

@trop

trop Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "43-x-y", please check out #51901

@trop trop Bot added the in-flight/43-x-y label Jun 5, 2026
@trop trop Bot removed the target/43-x-y PR should also be added to the "43-x-y" branch. label Jun 5, 2026
@trop

trop Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "41-x-y", please check out #51902

@trop

trop Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "42-x-y", please check out #51903

@trop trop Bot added in-flight/41-x-y in-flight/42-x-y and removed target/41-x-y PR should also be added to the "41-x-y" branch. target/42-x-y PR should also be added to the "42-x-y" branch. labels Jun 5, 2026
@KanishkRanjan

Copy link
Copy Markdown
Contributor Author

Thank you for your time and reviews. 🙂

@trop trop Bot added merged/43-x-y PR was merged to the "43-x-y" branch. merged/42-x-y PR was merged to the "42-x-y" branch. merged/41-x-y PR was merged to the "41-x-y" branch. and removed in-flight/43-x-y in-flight/42-x-y in-flight/41-x-y labels Jun 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged/41-x-y PR was merged to the "41-x-y" branch. merged/42-x-y PR was merged to the "42-x-y" branch. merged/43-x-y PR was merged to the "43-x-y" branch. semver/patch backwards-compatible bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invoking devtools from native menu should open devtools for the focused webContents

5 participants