Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new headless to lanuch options #628

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/Browser/BrowserProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,14 @@ private function getArgsFromOptions($binary, array $options)
}

// enable headless mode
if (!\array_key_exists('headless', $options) || $options['headless']) {
$args[] = '--headless';
$args[] = '--disable-gpu';
$args[] = '--font-render-hinting=none';
$args[] = '--hide-scrollbars';
$args[] = '--mute-audio';
if (!array_key_exists('headless', $options) || $options['headless']) {
$args[] = $options['headless'] === 'new' ? '--headless=new' : '--headless';
$args = array_merge($args, [
'--disable-gpu',
'--font-render-hinting=none',
'--hide-scrollbars',
'--mute-audio'
]);
}

// disable loading of images (currently can't be done via devtools, only CLI)
Expand Down
13 changes: 13 additions & 0 deletions tests/BrowserFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,17 @@ public function testConnectToBrowser(): void
$target = $browser2->getTarget($page2TargetId);
self::assertInstanceOf(Target::class, $target);
}

public function testHeadlessNewModeOptionExists(): void
{
$launchOptions = [
'headless' => 'new'
];

$factory = new BrowserFactory();

$factory->addOptions($launchOptions);

self::assertSame($launchOptions, $factory->getOptions());
}
}
20 changes: 20 additions & 0 deletions tests/PageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -507,4 +507,24 @@ public function testSetScriptExecution(): void
$page->evaluate('document.body.innerText')->getReturnValue()
);
}

public function testNewHeadlessModeNavigation(): void
{
$factory = new BrowserFactory();

$factory->addOptions([
'headless' => 'new'
]);

$browser = $factory->createBrowser();
$page = $browser->createPage();

$page->navigate(self::sitePath(self::WAIT_FOR_ELEMENT_RESOURCE_FILE))->waitForNavigation();

self::assertStringNotContainsString(self::WAIT_FOR_ELEMENT_HTML, $page->getHtml());

$page->waitUntilContainsElement('div[data-name=\"el\"]');

self::assertStringContainsString(self::WAIT_FOR_ELEMENT_HTML, $page->getHtml());
}
}