Skip to content
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

[Problem/Bug]: FrameCreated event sometimes doesn't fire for nested iframes #5115

Open
pushkin- opened this issue Feb 18, 2025 · 2 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@pushkin-
Copy link

What happened?

I'm seeing this issue in my app maybe 40-50% of the time, but in the WebView2 sample, I see it 100% of the time.

This might be specific to this website, but I'm seeing cases where FrameCreated isn't firing for a nested iframe.

For my general usecase, I haven't seen this problem, but since I don't know if this could start happening for the page I load in iframes, I'm marking this as Important out of caution. If we determine that this happens because of this specific site, then we can mark this Low.

Importance

Important. My app's user experience is significantly compromised.

Runtime Channel

Prerelease (Edge Canary/Dev/Beta)

Runtime Version

135.0.3146.0 canary

SDK Version

1.0.3116 pre-release

Framework

Winforms

Operating System

Windows 11

OS Version

24H2 OS Build 26100.2894

Repro steps

Setup:

  1. open the WebView2 Sample WinForms app
  2. In BrowserForm.cs, replace the body of WebView_HandleIFrames with:
var frame = args.Frame;
if (frame.Name == "myFrame")
{
    var breakHere = true;
}
frame.FrameCreated += WebView_HandleIFrames;
  1. Set a breakpoint on the breakHere variable

Repro steps:

  1. start the app and navigate to https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_iframe
  2. Replace the iframe in that page with: <iframe src="https://example.com" name="myFrame"></iframe>
  3. Notice that the breakpoint doesn't get hit

Alternatively, if you open devtools on that page and run this code: const a = document.createElement("iframe"); a.name = "myFrame"; a.src = "https://example.com"; document.body.appendChild(a);, then the breakpoint will get hit.

Like I said above, in my app, I see this roughly half the time, but can repro every time in the webview2 sample app. Maybe some kind of race condition?
Notably, this page creates a ton of iframes. Maybe this doesn't repro with a simpler page.

Repros in Edge Browser

No, issue does not reproduce in the corresponding Edge version

Regression

No, this never worked

Last working version (if regression)

No response

@pushkin- pushkin- added the bug Something isn't working label Feb 18, 2025
@sivMSFT
Copy link

sivMSFT commented Feb 19, 2025

Hi @pushkin-,

Could you try using the alternative:

Consider using the NestedFrameCreated event handler in CoreWebView2. This event will fire for all nested frame created events on CoreWebView2. You can subscribe to the CoreWebView2::NestedFrameCreated event to track all nested frames.

Example:

webView2.CoreWebView2.add_NestedFrameCreated(
    new EventHandler<CoreWebView2FrameCreatedEventArgs>((sender, args) =>
    {
        var frame = args.Frame;
        if (frame.Name == "myFrame")
        {
            var breakHere = true;
        }
    })); 

Please let us know, if this works for you.

@pushkin-
Copy link
Author

pushkin- commented Feb 19, 2025

What is NestedFrameCreated? Are you talking about the FrameCreated event that I can subscribe to on the Frame object? This is exactly what I'm doing in my example. @sivMSFT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants