Skip to main content

Frame

At every point of time, page exposes its current frame tree via the Page.mainFrame() and Frame.childFrames() methods.

Frame object's lifecycle is controlled by three events, dispatched on the page object:

An example of dumping frame tree:

import com.microsoft.playwright.*;

public class Example {
public static void main(String[] args) {
try (Playwright playwright = Playwright.create()) {
BrowserType firefox = playwright.firefox();
Browser browser = firefox.launch();
Page page = browser.newPage();
page.navigate("https://www.google.com/chrome/browser/canary.html");
dumpFrameTree(page.mainFrame(), "");
browser.close();
}
}
static void dumpFrameTree(Frame frame, String indent) {
System.out.println(indent + frame.url());
for (Frame child : frame.childFrames()) {
dumpFrameTree(child, indent + " ");
}
}
}

Methods

addScriptTag

Added before v1.9 frame.addScriptTag

Returns the added tag when the script's onload fires or when the script content was injected into frame.

Adds a