You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: specs/CDPSessionIdSupport.md
+57-45Lines changed: 57 additions & 45 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,22 +4,23 @@ sessionId support for DevToolsProtocol method call and event
4
4
# Background
5
5
A web page can have multiple DevToolsProtocol targets. Besides the default target for the top page, there are separate targets for iframes from different origin and web workers.
6
6
7
-
The underlying DevToolsProtocol supports interaction with other targets by attaching to them and then using sessionId of the attachment in DevToolsProtocol method call message.
8
-
The received DevToolsProtocol event messages also have sessionId field to indicate which target the event comes from.
7
+
The underlying DevToolsProtocol supports interaction with other targets by calling the `Target.setAutoAttach` method or the `Target.attachToTarget` method with an explicit targetId which returns a sessionId. The sessionId is also part of `Target.attachedToTarget` event message. Regardless of how the sessionId is obtained, it can be used
8
+
in subsequent DevToolsProtocol methods to indicate which session (and therefore which target) the method applies to.
9
9
See [DevToolsProtocol Target domain](https://chromedevtools.github.io/devtools-protocol/tot/Target/) for more details.
10
10
11
+
The DevToolsProtocol event messages also have sessionId field to indicate which target the event comes from.
12
+
11
13
However, the current WebView2 DevToolsProtocol APIs like [CallDevToolsProtocolMethod](https://docs.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2#calldevtoolsprotocolmethod)
12
14
and [DevToolsProtocolEventReceived](https://docs.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2devtoolsprotocoleventreceivedeventargs)
13
15
doesn't support sessionId.
14
16
15
-
To support interaction with different parts of the page, we are adding support for specifying sessionId for DevToolsProtocol method call API
16
-
and retrieving sessionId for received DevToolsProtocol events.
17
-
17
+
To support interaction with different parts of the page, we allow apps to specify a sessionId when calling DevToolsProtocol methods, as well as passing a sessionId to DevToolsProtocol event handlers, with empty string sessionId representing the default target of the top page.
18
+
18
19
# Conceptual pages (How To)
19
20
20
-
To use the sessionId support, you must attach to targets with with `flatten` set as `true` when calling `Target.attachToTarget` or `Target.setAutoAttach`.
21
+
To use the sessionId support, you must attach to targets with with `flatten` set as `true` when calling `Target.attachToTarget` or `Target.setAutoAttach`. Setting `flatten` as `false` is not supported. If attaching to a target with `flatten` set as `false`, the complete handler will never be invoked when calling DevToolsProtocol methods, and no events will be received from that session.
21
22
22
-
You can listen to `Target.attachedToTarget` and `Target.detachedFromTarget` events to manage the sessionId for targets, and listen to `Target.targetInfoChanged` event to update target info like url of a target.
23
+
You can listen to `Target.attachedToTarget` and `Target.detachedFromTarget` events to manage the sessionId for targets, and listen to `Target.targetInfoChanged` event to update target info like url of a target. To filter to specific frames or workers, you could use type, url and title of the target info.
23
24
24
25
There is also some nuance for DevToolsProtocol's target management. If you are interested in only top page and iframes from different origins on the page, it will be simple and straight forward. All related methods and events like `Target.getTargets`, `Target.attachToTarget`, and `Target.targetCreated` event work as expected.
25
26
@@ -34,6 +35,8 @@ To summarize, there are two ways of finding the targets and neither covers all 3
Also note that all of these methods apply only to direct children. To interact with grandchildren (like a different orign iframe inside a different origin iframe), you have to repeat recursively through the child targets.
39
+
37
40
# Examples
38
41
39
42
The example below illustrates how to collect messages logged by console.log calls by JavaScipt code from various parts of the web page, including dedicated web worker.
0 commit comments