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

Cannot yet tell if frame is final #398

Closed
svb91 opened this issue Jul 18, 2022 · 9 comments
Closed

Cannot yet tell if frame is final #398

svb91 opened this issue Jul 18, 2022 · 9 comments
Labels

Comments

@svb91
Copy link

svb91 commented Jul 18, 2022

Hi,

unfortunately I have some problems running your code (sometimes). I already tried to run the browser in non-headless-mode where I see, that the browser is running. Then I received a ton of exceptions until the 5s timeout. I have days where I can run the same code without any problem and - like today - it will not work regardless what I do.

How can I fix this error?

Exceptions during runtime (before the 5s timeout):

Cannot yet tell if frame is final
Cannot yet tell expected length
Cannot get extended length: need more data
Cannot get extended length: need more data
Cannot get extended length: need more data
Cannot get extended length: need more data
Cannot get extended length: need more data
Cannot yet tell if frame is final
Cannot yet tell expected length
Cannot get extended length: need more data
Cannot get extended length: need more data
Cannot get extended length: need more data
Cannot get extended length: need more data
Cannot get extended length: need more data
Cannot yet tell if frame is final
Cannot yet tell expected length
Cannot get extended length: need more data
Cannot get extended length: need more data
Cannot get extended length: need more data
Cannot get extended length: need more data
Cannot get extended length: need more data
Cannot yet tell if frame is final
Cannot yet tell expected length

Error Output:

Fatal error: Uncaught HeadlessChromium\Exception\OperationTimedOut: Operation timed out after 5s. in \composer\vendor\chrome-php\chrome\src\Exception\OperationTimedOut.php:18 Stack trace:
#0 \composer\vendor\chrome-php\chrome\src\Utils.php(67): HeadlessChromium\Exception\OperationTimedOut::createFromTimeout()
#1 \composer\vendor\chrome-php\chrome\src\Communication\ResponseReader.php(115): HeadlessChromium\Utils::tryWithTimeout()
#2 \composer\vendor\chrome-php\chrome\src\Communication\Connection.php(270): HeadlessChromium\Communication\ResponseReader->waitForResponse()
#3 \composer\vendor\chrome-php\chrome\src\Browser.php(84): HeadlessChromium\Communication\Connection->sendMessageSync()
#4 \composer\vendor\chrome-php\chrome\src\Browser\ProcessAwareBrowser.php(26): HeadlessChromium\Browser->__construct()
#5 \composer\vendor\chrome-php\chrome\src\Browser\BrowserProcess.php(162): HeadlessChromium\Browser\ProcessAwareBrowser->__construct()
#6 \composer\vendor\chrome-php\chrome\src\BrowserFactory.php(81): HeadlessChromium\Browser\BrowserProcess->start()
#7 \php\classes\main\main\screenshot.class.php(39): HeadlessChromium\BrowserFactory->createBrowser()
#8 \index.php(52): screenshot::createScreenshot()
#9 C:_Private Data - NO BACKUP\Source\web_template\index.php(238): include('...') #10 {main} thrown in \composer\vendor\chrome-php\chrome\src\Exception\OperationTimedOut.php on line 18

Fatal error: Uncaught Error: Call to a member function sendCloseMessage() on null in \composer\vendor\chrome-php\chrome\src\Browser\BrowserProcess.php:210 Stack trace:
#0 [internal function]: HeadlessChromium\Browser\BrowserProcess->kill() #1 {main} thrown in \composer\vendor\chrome-php\chrome\src\Browser\BrowserProcess.php on line 210

Chrome Log:

[2022-07-18T09:01:02.471511+02:00] chrome.DEBUG: process: initializing [] []
[2022-07-18T09:01:02.477975+02:00] chrome.DEBUG: process: using directory: C:\Users\vanboxemsi\AppData\Local\Temp\chr26D9.tmp [] []
[2022-07-18T09:01:02.484123+02:00] chrome.DEBUG: process: starting process: "C:\Program Files\Google\Chrome\Application\chrome.exe" --remote-debugging-port=0 --disable-background-networking --disable-background-timer-throttling --disable-client-side-phishing-detection --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-translate --disable-features=ChromeWhatsNewUI --metrics-recording-only --no-first-run --safebrowsing-disable-auto-update --enable-automation --password-store=basic --use-mock-keychain --headless --disable-gpu --font-render-hinting=none --hide-scrollbars --mute-audio --window-size=1920,1080 --user-data-dir=C:\Users\vanboxemsi\AppData\Local\Temp\chr26D9.tmp [] []
[2022-07-18T09:01:02.503449+02:00] chrome.DEBUG: process: waiting for 30 seconds for startup [] []
[2022-07-18T09:01:02.984082+02:00] chrome.DEBUG: process: chrome output:DevTools listening on ws://127.0.0.1:54291/devtools/browser/dac28e17-7831-490d-8022-5d3e96d516e7 [] []
[2022-07-18T09:01:02.984441+02:00] chrome.DEBUG: process: ✓ accepted output [] []
[2022-07-18T09:01:02.984781+02:00] chrome.DEBUG: process: connecting using ws://127.0.0.1:54291/devtools/browser/dac28e17-7831-490d-8022-5d3e96d516e7 [] []
[2022-07-18T09:01:03.001490+02:00] chrome.DEBUG: socket(1): connecting [] []
[2022-07-18T09:01:03.005447+02:00] chrome.DEBUG: socket(1): ✓ connected [] []
[2022-07-18T09:01:03.008457+02:00] chrome.DEBUG: socket(1): → sending data:{"id":1,"method":"Target.setDiscoverTargets","params":{"discover":true}} [] []
[2022-07-18T09:01:10.021920+02:00] chrome.DEBUG: socket(1): ← receiving data:{"method":"Target.targetCreated","params":{"targetInfo":{"targetId":"0180368f-8317-4220-b781-c25ae8d54c80","type":"browser","title":"","url":"","attached":true,"canAccessOpener":false}}} [] []
[2022-07-18T09:01:10.022309+02:00] chrome.DEBUG: socket(1): ← receiving data:{"method":"Target.targetCreated","params":{"targetInfo":{"targetId":"2cb9652a-f99d-4604-ba4f-8b237e191d0e","type":"browser","title":"","url":"","attached":false,"canAccessOpener":false}}} [] []
[2022-07-18T09:01:10.022638+02:00] chrome.DEBUG: socket(1): ← receiving data:{"method":"Target.targetCreated","params":{"targetInfo":{"targetId":"3A2C028723376A2165D985B844E5133E","type":"page","title":"","url":"about:blank","attached":false,"canAccessOpener":false,"browserContextId":"9D37FF0DE883F6D12504250B5681FAC9"}}} [] []
[2022-07-18T09:01:10.023208+02:00] chrome.DEBUG: socket(1): ← receiving data:{"id":1,"result":{}} [] []
[2022-07-18T09:01:10.023476+02:00] chrome.DEBUG: connection: ⇶ dispatching method:Target.targetCreated [] []
[2022-07-18T09:01:10.933292+02:00] chrome.DEBUG: process: killing chrome [] []
[2022-07-18T09:01:10.933574+02:00] chrome.DEBUG: process: trying to close chrome gracefully [] []
@enricodias
Copy link
Member

To verify if it's a problem with the library, we need to be able to reproduce the problem at our end. Your logs just shows a normal timeout, meaning that the chrome process didn't reply fast enough. Can you provide a sample code that leads to the errors you mentioned?

@svb91
Copy link
Author

svb91 commented Jul 18, 2022

Sure. I've created a custom wrapper for your tool. The strange thing is, that the exact same code sometimes worked 20x and right now it does not work. I already tried to change timeouts but the exceptions will be thrown after a few seconds (bellow the timeout limit)

In my Index i run the following code:

screenshot::createScreenshot("https://github.com/chrome-php/chrome", "test.jpg");
First parameter is the URL and the second the output file.

Relevant code of the function (The code does not reach the try-block):

// starts headless chrome
$o_browserFactory	= new BrowserFactory();
$o_browser		= $o_browserFactory->createBrowser([	'windowSize' => [1920, 1080],
								'noSandbox' => true]);




// Perform Request
try
{
	// Navigate to page
	$o_page = $o_browser->createPage();
	$o_page->navigate($s_url)->waitForNavigation();




	// Screenshot Settings
	$S_screenshotData = array(	"format" => "jpeg"
					"quality" => $i_quality);



	// Take Screenshot
	$o_screenshot = $o_page -> screenshot($S_screenshotData);




	// Save to File
	$o_screenshot->saveToFile($s_destination);
}
catch(Exception $e)
{
	// Return Error
        return false;
}

// Return OK
return true;

@enricodias
Copy link
Member

Are you executing this code in parallel? Can you test it using the version 1.4?

@svb91
Copy link
Author

svb91 commented Jul 19, 2022

I tested all versions and the same error occurred beginning with version 0.10.0.
In version 0.9.0 the error changed to:

Fatal error: Uncaught RuntimeException: Chrome process stopped before startup completed. Additional info: Der Befehl "chrome" ist entweder falsch geschrieben oder konnte nicht gefunden werden.

And I don't run the code in parallel.

The interesting part is, that I don't have the feeling of changing any setting in chrome (not my default browser, so it is only used by your script) but sometimes it worked without any problem...

@enricodias
Copy link
Member

enricodias commented Jul 19, 2022

When you execute in non-headless-mode, does the browser remains alive after the error? I'm thinking that something else may be killing your chrome process.

@svb91
Copy link
Author

svb91 commented Jul 20, 2022

The browser remains open for the full 5s till the timeout.
Than it will be closed by your script.
There shouldnt be any other processes killing chrome.

Is it maybe an anti-virus-related issue? This script is running on a company device and we use MS Defender

@horror
Copy link

horror commented Jul 27, 2022

same issue. browser version 103.0.5060.134-1. package 1.6.1

@enricodias
Copy link
Member

I executed this exact code and couldn't reproduce the error:

include 'vendor/autoload.php';

use HeadlessChromium\BrowserFactory;

$s_url = 'https://github.com/chrome-php/chrome';
$i_quality = 90;
$s_destination = 'test.jpg';

$o_browserFactory = new BrowserFactory();
$o_browser = $o_browserFactory->createBrowser([
    'windowSize' => [1920, 1080],
    'noSandbox' => true,
]);

try {
    $o_page = $o_browser->createPage();
    $o_page->navigate($s_url)->waitForNavigation();

    $o_screenshot = $o_page->screenshot([
        'format' => 'jpeg',
        'quality' => $i_quality,
    ]);

    $o_screenshot->saveToFile($s_destination);
} catch (Exception $e) {
    // Return Error
}

It's probably something related to your specific setup. The fatal error when calling sendCloseMessage() is caused by the $browser property in the BrowserProcess::class being null, but there is nothing in this lib that sets it to null. The only way to see whats happening is to reproduce the error and follow the code execution step by step with xdebug.

@stale
Copy link

stale bot commented Feb 5, 2023

This issue has been automatically marked as stale because there has been no recent activity. It will be closed after 30 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Feb 5, 2023
@stale stale bot closed this as completed Mar 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants