@@ -40,7 +40,7 @@ the frame running in this webview or webview frame.
4040
4141* We propose extending ` CoreWebView2FrameInfo ` to include ` FrameId ` and
4242` ParentFrameInfo ` properties. ` FrameId ` is the same kind of ID as with
43- frame ID in ` CoreWebView2 ` and ` CoreWebView2Frame ` . ` ParentFrameInfo `
43+ ` FrameID ` in ` CoreWebView2 ` and ` CoreWebView2Frame ` . ` ParentFrameInfo `
4444supports to retrive a frame's direct parent, corresponding parent frame
4545in the first level and corresponding main frame. This also can be used
4646to build the architecture of the frame tree with represent by ` FrameInfo ` .
@@ -265,14 +265,18 @@ void ProcessComponent::AppendAncestorFrameInfo(
265265```
266266C#
267267```c#
268- string AppendFrameInfo(string id, string name, string kind, string parentId, string source,
269- string ancestorMainFrameId, string ancestorFirstLevelFrameId) {
268+ string AppendFrameInfo(CoreWebView2FrameInfo frameInfo, string kind, string mainFrameId, string firstLevelFrameId) {
269+ string id = frameInfo.FrameId.ToString();
270+ string name = String.IsNullOrEmpty(frameInfo.Name) ? "none" : frameInfo.Name;
271+ string source = String.IsNullOrEmpty(frameInfo.Source) ? "none" : frameInfo.Source;
272+ string parentId = frameInfo.ParentFrameInfo == null ? "none" : frameInfo.ParentFrameInfo.FrameId.ToString();
273+
270274 return $"{{frame Id:{id} " +
271275 $"| frame Name: {name} " +
272276 $"| frame Kind: {kind} " +
273277 $"| parent frame Id: {parentId} " +
274- $"| ancestor main frame Id: {ancestorMainFrameId } " +
275- $"| ancestor first level frame Id: {ancestorFirstLevelFrameId } " +
278+ $"| ancestor main frame Id: {mainFrameId } " +
279+ $"| ancestor first level frame Id: {firstLevelFrameId } " +
276280 $"| frame Source: \"{source}\"}}\n";
277281}
278282
@@ -301,45 +305,36 @@ private async void ProcessFrameInfoCmdExecuted(object target, ExecutedRoutedEven
301305 IReadOnlyList<CoreWebView2FrameInfo> frameInfoList = processList[i].AssociatedFrameInfos;
302306 foreach (CoreWebView2FrameInfo frameInfo in frameInfoList)
303307 {
304- string parentFrameId = "Not Existed";
305- string ancestorMainFrameId = "Not Existed";
306- string ancestorFirstLevelFrameId = "Not Existed";
307- string frameSource = frameInfo.Source;
308- string frameId = frameInfo.FrameId.ToString();
309- string frameName = frameInfo.Name;
308+ string ancestorMainFrameId = "none";
309+ string ancestorFirstLevelFrameId = "none";
310310 CoreWebView2FrameInfo parentFrameInfo = frameInfo.ParentFrameInfo;
311- if (parentFrameInfo != null)
312- {
313- parentFrameId = parentFrameInfo.FrameId.ToString();
314- }
315-
316311 frameInfoCount++;
317312 // If the frame has no parent, then it's a main frame.
318313 if (parentFrameInfo == null)
319314 {
320315 ancestorMainFrameId = frameInfo.FrameId.ToString();
321- frameInfosStr += AppendFrameInfo(frameId, frameName, "main frame", parentFrameId, frameSource , ancestorMainFrameId, ancestorFirstLevelFrameId);
316+ frameInfosStr += AppendFrameInfo(frameInfo, "main frame", ancestorMainFrameId, ancestorFirstLevelFrameId);
322317 continue;
323318 }
324- CoreWebView2FrameInfo firstLevelFrameInfo = parentFrameInfo;
325- parentFrameInfo = parentFrameInfo.ParentFrameInfo;
319+
320+ CoreWebView2FrameInfo mainFrameInfo = parentFrameInfo;
321+ CoreWebView2FrameInfo firstLevelFrameInfo = frameInfo;
326322 // If the frame's parent has no parent frame, then it's a first level frame.
327- if (parentFrameInfo == null)
328- {
329- ancestorMainFrameId = frameInfo.FrameId.ToString();
330- ancestorFirstLevelFrameId = frameInfo.ParentFrameInfo.FrameId.ToString();
331- frameInfosStr += AppendFrameInfo(frameId, frameName, "first level frame frame", parentFrameId, frameSource, ancestorMainFrameId, ancestorFirstLevelFrameId);
323+ if (mainFrameInfo.ParentFrameInfo == null) {
324+ ancestorMainFrameId = mainFrameInfo.FrameId.ToString();
325+ ancestorFirstLevelFrameId = firstLevelFrameInfo.FrameId.ToString();
326+ frameInfosStr += AppendFrameInfo(frameInfo, "first level frame", ancestorMainFrameId, ancestorFirstLevelFrameId);
332327 continue;
333328 }
334329 // For other child frames, we traverse the parent frame until find the ancestor main frame.
335- while (parentFrameInfo.ParentFrameInfo != null)
336- {
337- firstLevelFrameInfo = parentFrameInfo;
338- parentFrameInfo = parentFrameInfo.ParentFrameInfo;
330+ while (mainFrameInfo.ParentFrameInfo != null) {
331+ firstLevelFrameInfo = mainFrameInfo;
332+ mainFrameInfo = mainFrameInfo.ParentFrameInfo;
339333 }
340- ancestorMainFrameId = parentFrameInfo.FrameId.ToString();
334+
335+ ancestorMainFrameId = mainFrameInfo.FrameId.ToString();
341336 ancestorFirstLevelFrameId = firstLevelFrameInfo.FrameId.ToString();
342- frameInfosStr += AppendFrameInfo(frameId, frameName, "other frame", parentFrameId, frameSource , ancestorMainFrameId, ancestorFirstLevelFrameId);
337+ frameInfosStr += AppendFrameInfo(frameInfo, "other frame", ancestorMainFrameId, ancestorFirstLevelFrameId);
343338 }
344339 // </AssociatedFrameInfos>
345340 string rendererProcessInfoStr = $"{frameInfoCount} frame info(s) found in renderer process ID: {processId}\n {frameInfosStr}";
@@ -416,17 +411,20 @@ interface ICoreWebView2Environment14 : ICoreWebView2Environment13 {
416411// / A continuation of the ICoreWebView2FrameInfo interface.
417412[uuid(a7a7e150-e2ca-11ed-b5ea-0242ac120002), object, pointer_default(unique)]
418413interface ICoreWebView2FrameInfo2 : ICoreWebView2FrameInfo {
419- /// The parent ` FrameInfo ` . This property is ` null ` for the top most document in the
420- /// WebView2 which has no parent frame. This is only available when it's called from
421- /// ` ICoreWebView2GetProcessInfosWithDetailsCompletedHandler ` . Else, it returns ` null ` .
422- /// Note that this parent frame info could be out of date as it's a snapshot.
414+ /// The parent ` FrameInfo ` . ` ParentFrameInfo ` will only be populated when obtained
415+ /// via calling ` CoreWebView2ProcessInfo.AssociatedFrameInfos ` .
416+ /// ` CoreWebView2FrameInfo ` objects obtained via ` CoreWebView2.ProcessFailed ` will
417+ /// always have a ` null ` ` ParentFrameInfo ` . This property is also ` null ` for the
418+ /// top most document in the WebView2 which has no parent frame.
419+ /// Note that this ` ParentFrameInfo ` could be out of date as it's a snapshot.
423420 [ propget] HRESULT ParentFrameInfo([ out, retval] ICoreWebView2FrameInfo** frameInfo);
424421 /// The unique identifier of the frame associated with the current ` FrameInfo ` .
425- /// It's the same kind of ID as with the frame ID in ` ICoreWebView2 ` and
426- /// ` ICoreWebView2Frame ` . This is only available when it's called from
427- /// ` ICoreWebView2GetProcessInfosWithDetailsCompletedHandler ` . Else, it returns
428- /// an invalid frame ID ` 0 ` .
429- /// Note that this frame ID could be out of date as it's a snapshot.
422+ /// It's the same kind of ID as with the ` FrameId ` in ` ICoreWebView2 ` and via
423+ /// ` ICoreWebView2Frame ` . ` FrameId ` will only be populated when obtained
424+ /// calling ` CoreWebView2ProcessInfo.AssociatedFrameInfos ` .
425+ /// ` CoreWebView2FrameInfo ` objects obtained via ` CoreWebView2.ProcessFailed ` will
426+ /// always have an invalid frame Id 0.
427+ /// Note that this ` FrameId ` could be out of date as it's a snapshot.
430428 [ propget] HRESULT FrameId([ out, retval] UINT32* id);
431429}
432430
@@ -441,8 +439,8 @@ interface ICoreWebView2Frame5: ICoreWebView2Frame4 {
441439[uuid(ad712504-a66d-11ed-afa1-0242ac120002), object, pointer_default(unique)]
442440interface ICoreWebView2_18 : ICoreWebView2_17 {
443441 /// The unique identifier of the current frame.
444- /// Note that frame Id is not valid if ` ICoreWebView ` has not started
445- /// a navigation. It returns an error code ` E_FAIL ` .
442+ /// Note that ` FrameId ` is not valid if ` ICoreWebView ` has not done
443+ /// any navigation. It returns an invalid frame Id 0.
446444 [ propget] HRESULT FrameId([ out, retval] UINT32* id);
447445}
448446```
0 commit comments