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 <script> tag into the page with the desired url or content.

Usage

Frame.addScriptTag();
Frame.addScriptTag(options);

Arguments

  • options Frame.AddScriptTagOptions (optional)
    • setContent String (optional)#

      Raw JavaScript content to be injected into frame.

    • setPath Path (optional)#

      Path to the JavaScript file to be injected into frame. If path is a relative path, then it is resolved relative to the current working directory.

    • setType String