Skip to content

feat: WebContents.getOrCreateDevToolsTargetId()#49733

Merged
jkleinsc merged 5 commits into
electron:mainfrom
kycutler:kycutler/devtoolsid
Mar 9, 2026
Merged

feat: WebContents.getOrCreateDevToolsTargetId()#49733
jkleinsc merged 5 commits into
electron:mainfrom
kycutler:kycutler/devtoolsid

Conversation

@kycutler
Copy link
Copy Markdown
Contributor

@kycutler kycutler commented Feb 10, 2026

Background

In VS Code we are working on a CDP implementation to manage multiple WebContentsViews. We need to implement methods like getTargets that list the real targetIds of all available WebContents. Ideally we can do this synchronously and without attaching to every WebContents. But currently the only way to get the target ID of a WebContents is by attaching to it and calling e.g. Target.getTargetInfo.

Description of Change

There is an existing static method WebContents.fromDevToolsTargetId(devToolsId) that does the reverse lookup. This PR adds a method on WebContents to get the target ID directly (and synchronously).

Checklist

Release Notes

Notes: Added webContents.getOrCreateDevToolsTargetId().

@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Feb 10, 2026
@codebytere codebytere added semver/minor backwards-compatible functionality api-review/requested 🗳 target/41-x-y PR should also be added to the "41-x-y" branch. labels Feb 10, 2026
@codebytere
Copy link
Copy Markdown
Member

@kycutler have you built and tested it? We don't allow PRs for which that's not true at the moment due to proliferation of poorly created AI PRs.

Comment thread shell/browser/api/electron_api_web_contents.cc Outdated
@kycutler kycutler changed the title feat: WebContents.getDevToolsTargetId() feat: WebContents.getOrCreateDevToolsTargetId() Feb 13, 2026
@deepak1556 deepak1556 self-requested a review February 13, 2026 20:52
@deepak1556 deepak1556 dismissed their stale review February 13, 2026 20:53

Thanks for sharing additional context on the feature requested, we don't have a utility to get expected target id of a webcontent without attaching.

@deepak1556 deepak1556 removed their request for review February 13, 2026 21:55
@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Feb 17, 2026
@kycutler kycutler requested review from a team as code owners February 26, 2026 18:20
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Hello @kycutler! It looks like this pull request touches one of our dependency or CI files, and per our contribution policy we do not accept these types of changes in PRs.

@kycutler kycutler force-pushed the kycutler/devtoolsid branch from 666dc88 to db8b64b Compare February 26, 2026 18:23
@deepak1556 deepak1556 removed request for a team March 3, 2026 02:37
Copy link
Copy Markdown
Member

@deepak1556 deepak1556 left a comment

Choose a reason for hiding this comment

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

Implementation looks good, thanks for clarifying the use case! Still needs an api review

Copy link
Copy Markdown
Member

@jkleinsc jkleinsc left a comment

Choose a reason for hiding this comment

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

API LGTM

@kycutler kycutler force-pushed the kycutler/devtoolsid branch from bbae959 to e23dfdd Compare March 7, 2026 01:26
Copy link
Copy Markdown
Member

@erickzhao erickzhao left a comment

Choose a reason for hiding this comment

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

API LGTM

@jkleinsc jkleinsc merged commit 2ba4872 into electron:main Mar 9, 2026
109 of 110 checks passed
@release-clerk
Copy link
Copy Markdown

release-clerk Bot commented Mar 9, 2026

Release Notes Persisted

Added webContents.getOrCreateDevToolsTargetId().

@trop
Copy link
Copy Markdown
Contributor

trop Bot commented Mar 9, 2026

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

@trop trop Bot added in-flight/41-x-y merged/41-x-y PR was merged to the "41-x-y" branch. and removed target/41-x-y PR should also be added to the "41-x-y" branch. in-flight/41-x-y labels Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-review/approved ✅ merged/41-x-y PR was merged to the "41-x-y" branch. semver/minor backwards-compatible functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants