online method
Future<Online>
online(
{ - bool visible = true,
- Duration? slow,
- Duration? timeout,
- String? browserWSEndpoint,
- bool devtools = false,
- int width = 1920,
- int height = 1080,
- double scale = 1,
- bool isMobile = false,
- bool hasTouch = false,
})
Implementation
Future<Online> online({
bool visible = true,
Duration? slow,
Duration? timeout,
String? browserWSEndpoint,
bool devtools = false,
int width = 1920,
int height = 1080,
double scale = 1,
bool isMobile = false,
bool hasTouch = false,
}) async {
Browser browser;
final existingEndpoint = await findExistingChromeDevToolsEndpoint();
if (existingEndpoint != null) {
Show.info("connecting", "to", "existing",
"browser instance found at $existingEndpoint");
browser = await puppeteer.connect(
browserWsEndpoint: existingEndpoint,
slowMo: slow,
);
} else {
// If no existing browser is found, launch a new instance.
Show.info("launching", "new", "browser instance");
browser = await puppeteer.launch(
executablePath: await getBrowserPath(),
headless: !visible,
devTools: devtools,
defaultViewport: DeviceViewport(
width: width,
height: height,
deviceScaleFactor: scale,
isMobile: isMobile,
hasTouch: hasTouch),
args: [
'--remote-debugging-port=9222',
],
ignoreDefaultArgs: [
'--remote-debugging-port=9222',
'--disable-infobars',
'--disable-extensions',
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-web-security',
'--disable-features=IsolateOrigins,site-per-process',
'--disable-site-isolation-trials',
'--ignore-certificate-errors',
'--ignore-certificate-errors-spki-list',
'--disable-extensions',
'--disable-features=site-per-process',
'--disable-accelerated-2d-canvas',
'--disable-backgrounding-occluded-windows',
'--disable-background-timer-throttling',
'--disable-background-networking',
'--disable-renderer-backgrounding',
],
plugins: null,
timeout: timeout ?? Duration(minutes: 10),
slowMo: slow,
);
}
// Ensure that the browser is closed when the program exits.
browser.process?.exitCode.then((value) => browser.close());
return Online(
browser,
default_timeout: timeout ?? Duration(minutes: 5),
);
}