Sunday 2 July 2023

Playwright: launch installed chrome browser

By setting the channel to 'chrome', we can launch the page in local chrome browser.

 

Example

playwright
.chromium()
.launch(new BrowserType
			.LaunchOptions()
			.setHeadless(false)
			.setSlowMo(100)
			.setChannel("chrome"));

 

Following are the supported values for the channel.

 

chrome, chrome-beta, chrome-dev, chrome-canary, msedge, msedge-beta, msedge-dev, msedge-canary

 

a.   chrome,

b.   chrome-beta,

c.    chrome-dev,

d.   chrome-canary,

e.   msedge,

f.     msedge-beta,

g.   msedge-dev,

h.   msedge-canary

 

Find the below working application.

 

LaunchChromeBrowser.java

package com.sample.app.miscellaneous;

import com.microsoft.playwright.Browser;
import com.microsoft.playwright.BrowserType;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.Playwright;

public class LaunchChromeBrowser {

	public static void main(String[] args) throws InterruptedException {
		try (Playwright playwright = Playwright.create()) {
			Browser browser = playwright.chromium()
					.launch(new BrowserType.LaunchOptions().setHeadless(false).setSlowMo(100).setChannel("chrome"));
			Page page = browser.newPage();
			page.navigate("https://self-learning-java-tutorial.blogspot.com/2014/07/basic-java.html");
		}
	}

}

 

 

Previous                                                 Next                                                 Home

No comments:

Post a Comment