New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add webContents.fromDevToolsTargetId() #29399
feat: add webContents.fromDevToolsTargetId() #29399
Conversation
It might be easier to expose https://source.chromium.org/chromium/chromium/src/+/main:content/browser/renderer_host/frame_tree_node.h;l=118;bpv=0;bpt=1 instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API Looks good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API LGTM here as well, and agree with @nornagon above about webcontents creation.
@pavelfeldman Just so this doesn't go unaddressed, I'll look into binding this in another PR if I find it's needed for debugging specific frames. |
2a8324d
to
29bebdc
Compare
Discussion came up as to whether this is the right way forward for this API.
For this specific use case, we want to get the associated WebContents for a DevToolsAgentHost currently attached to a frame. We do so by looking up the DevToolsAgentHost by its unique TargetID. If it exists and is of the expected DevToolsAgentHost subclass, it will have a WebContents accessible from This approach is sufficient for the problem being solved. One alternative design would be to expand the capabilities of the interface Debugger {
/** Get a debugger from an existing, attached DevTools host ID. */
static fromTargetId(id: string): Debugger | undefined;
/** An alternative to webContents.fromDevToolsTargetId() */
webContents?: WebContents;
/**
* The type of DevToolsAgentHost.
* https://source.chromium.org/chromium/chromium/src/+/main:content/browser/devtools/devtools_agent_host_impl.cc;l=43-50;drc=2205e9942d2fc0ef177f6802683345a1822da88e
*/
type: 'page' | 'iframe' | 'worker' | 'shared_worker' | /* etc. */;
} With this approach, we could create a This is more complex and would involve careful memory considerations with a likely needed introduction of the I'm not currently aware of another use case that this design would solve so the complexity might not be worth it. Another exported module would be needed as well for the static method introduced to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-✅ , I think this approach is fine.
Release Notes Persisted
|
I have automatically backported this PR to "12-x-y", please check out #30730 |
I have automatically backported this PR to "13-x-y", please check out #30731 |
I have automatically backported this PR to "14-x-y", please check out #30732 |
I have automatically backported this PR to "15-x-y", please check out #30733 |
Description of Change
Playwright has experimental support for Electron which works pretty well for single BrowserWindow use cases. However, there are currently issues when multiple BrowserWindows are involved (microsoft/playwright#6760).
The proposed changes introduce the static method
webContents.fromDevToolsTargetId(targetId)
which allows for looking up a WebContents based on the stable DevTools TargetID.Using this method will allow Playwright to properly lookup WebContents instances and get their associated BrowserWindows.
Since this enables use cases in a third-party application, it'd be great to be backported to all actively supported versions of Electron (>=11).
Checklist
npm test
passesRelease Notes
Notes: Added
webContents.fromDevToolsTargetId(targetId)
to lookup a WebContents instance from an associated Chrome DevTools Protocol TargetID.