Skip to content

IFrame

Namespace: PuppeteerSharp

public interface IFrame

Provides methods to interact with a single page frame in Chromium. One IPage instance might have multiple IFrame instances. At every point of time, page exposes its current frame tree via the MainFrame and ChildFrames properties.

IFrame object’s lifecycle is controlled by three events, dispatched on the page object

  • FrameAttached - fires when the frame gets attached to the page. A Frame can be attached to the page only once
  • FrameNavigated - fired when the frame commits navigation to a different URL
  • FrameDetached - fired when the frame gets detached from the page. A Frame can be detached from the page only once.

Derived: BidiFrame, CdpFrame, Frame

Example

An example of dumping frame tree.

var browser = await Puppeteer.LaunchAsync(new LaunchOptions());
var page = await browser.NewPageAsync();
await page.GoToAsync("https://www.google.com/chrome/browser/canary.html");
dumpFrameTree(page.MainFrame, string.Empty);
await browser.CloseAsync();
void dumpFrameTree(IFrame frame, string indent)
{
Console.WriteLine(indent + frame.Url);
foreach (var child in frame.ChildFrames)
{
dumpFrameTree(child, indent + " ");
}
}

View source

Made with love by Dario Kondratiuk