// 一些相关jar包 import cn.hutool.core.collection.ListUtil; import cn.hutool.core.thread.ThreadUtil; import com.microsoft.playwright.*; import javax.annotation.Resource; import java.util.List; import java.util.concurrent.TimeUnit; String url = "https://www.baidu.com"; Playwright playwright = Playwright.create(); Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions() .setHeadless(false) // 取消无头模式,我们才能看见浏览器操作 // .setChannel("chrome") .setArgs(ListUtil.of("--start-maximized")) ); BrowserContext context = browser.newContext(new Browser.NewContextOptions().setViewportSize(null)); Page page = context.newPage(); page.navigate(url); ThreadUtil.sleep(5, TimeUnit.SECONDS); playwright.close();
打开2个chromium窗口,第1个窗口打开2个标签页面,第2个窗口打开1个标签页面
String url = "https://www.baidu.com"; Playwright playwright = Playwright.create(); Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions() .setHeadless(false) // 取消无头模式,我们才能看见浏览器操作 // .setChannel("chrome") .setArgs(ListUtil.of("--start-maximized")) ); BrowserContext context = browser.newContext(new Browser.NewContextOptions().setViewportSize(null)); Page page = context.newPage(); page.navigate(url); Page page1 = context.newPage(); page1.navigate(url); BrowserContext context2 = browser.newContext(new Browser.NewContextOptions().setViewportSize(null)); Page page2 = context2.newPage(); page2.navigate(url); ThreadUtil.sleep(15, TimeUnit.SECONDS); playwright.close();