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

Uncaught ReferenceError: Tracy is not defined #579

Closed
M4RtY opened this issue Apr 19, 2024 · 5 comments
Closed

Uncaught ReferenceError: Tracy is not defined #579

M4RtY opened this issue Apr 19, 2024 · 5 comments

Comments

@M4RtY
Copy link

M4RtY commented Apr 19, 2024

Version: 2.10

Bug Description

When I uploaded project to Linux hosted VPS witch Apache 2.4 everything works except the Tracy. I have checked the Apache configuration file but I do not see any difference that can cause this issue. I was trying to debug this Tracy source code and the stack trace says DeferredContent.php:76

  1. I can see that there is a echo $str that breaks the code and it is trying to get built CSS + JS
  2. I have dumped the $str and this looks fine - CSS + JS for tracy

Source code

if ($asset === 'js') {
	header('Content-Type: application/javascript; charset=UTF-8');
	header('Cache-Control: max-age=864000');
	header_remove('Pragma');
	header_remove('Set-Cookie');
	$str = $this->buildJsCss(); 
	header('Content-Length: ' . strlen($str));
	echo $str; <--- LINE 76 that returns error with sent header
	flush();
	return true;
}

Debug process

  1. When I dump the headers_list()
array(3) {
  [0] =>
  string(51) "Content-Type: application/javascript; charset=UTF-8"
  [1] =>
  string(29) "Cache-Control: max-age=864000"
  [2] =>
  string(21) "Content-Length: 60317"
} 

Stack Trace

Nette\InvalidStateException: Cannot send header after HTTP headers have been sent (output started at /var/www/clients/client0/web7/web/vendor/tracy/tracy/src/Tracy/Debugger/DeferredContent.php:76). in /var/www/clients/client0/web7/web/vendor/nette/http/src/Http/Response.php:274
Stack trace:
#0 /var/www/clients/client0/web7/web/vendor/nette/http/src/Http/Response.php(85): Nette\Http\Response->checkHeaders()
#1 /var/www/clients/client0/web7/web/temp/cache/nette.configurator/Container_7376f82586.php(2652): Nette\Http\Response->setHeader('...', '...')
#2 /var/www/clients/client0/web7/web/temp/cache/nette.configurator/Container_7376f82586.php(2656): Container_7376f82586->{closure}()
#3 /var/www/clients/client0/web7/web/vendor/nette/bootstrap/src/Bootstrap/Configurator.php(241): Container_7376f82586->initialize()
#4 /var/www/clients/client0/web7/web/www/index.php(10): Nette\Bootstrap\Configurator->createContainer()
#5 {main}

Steps To Reproduce

URL: https://pisnickycz.pepiapp.sk/

Expected Behavior

The expecte behavior is to show the Tracy - it is enabled and should work.

Possible Solution

I do not know yet.

@dg
Copy link
Member

dg commented Apr 19, 2024

After executing echo $str, an exit should be called in Debugger::dispatch() and the application should terminate. It's a mystery to me why it continues, why a DI container is created, and then that error occurs. Try stepping through it.

@M4RtY
Copy link
Author

M4RtY commented Apr 19, 2024

Yes, this is very strange, because other headers are fine, there is a problem with the Tracy only. I was trying to change PHP versions (FastCGI, PFM) and there is no difference.

I have found some configuration issue for Nginx, but there was also mentioned that Tracy works on "index", for me the Tracy does not work for whole website.

StackTrace #0 - Nette\Http\Response->checkHeaders()

$value = string(17) "Nette Framework 3" for both environments
$name = string(12) "X-Powered-By" for both environments

if ($value === null) {
	header_remove($name);
} elseif (strcasecmp($name, 'Content-Length') === 0 && ini_get('zlib.output_compression')) {
	// ignore, PHP bug #44164
} else {
	header($name . ': ' . $value); <-- this line is executed (both environments - var_dump() here)
}

I dumped headers_list() here and there is one output both both environments:

array(1) {
  [0] =>
  string(31) "X-Powered-By: Nette Framework 3"
}

** StackTrace #1 a #2 - Nette\Http\Response->setHeader('...', '...')**

public function initialize(): void
{
// di.
(function () {
	$this->getService('tracy.bar')->addPanel(new Nette\Bridges\DITracy\ContainerPanel($this));
})();
// forms.
(function () {
	Nette\Forms\Validator::$messages[Nette\Forms\Form::EMAIL] = 'Zadejte platnou e-mailovou adresu.';
})();
// http.
(function () {
	$response = $this->getService('http.response');
	$response->setHeader('X-Powered-By', 'Nette Framework 3'); <--- LINE 2652
	$response->setHeader('Content-Type', 'text/html; charset=utf-8');
	$response->setHeader('X-Frame-Options', 'SAMEORIGIN');
	Nette\Http\Helpers::initCookie($this->getService('http.request'), $response);
})();  <--- LINE 2656

The thing is that there is nothing strange for me in this case and I am not sure how to continue with the debugging. At least, I can provide the affected environment or if you can gouide me what to do more, it would be great.

I was expecting that this "header" issue is for whole website, but only Tracy has this problem

@M4RtY
Copy link
Author

M4RtY commented Apr 19, 2024

Also I have noticed the output in the browser:

URL: view-source:https://pisnickycz.pepiapp.sk/?_tracy_bar=js&v=2.10.5&XDEBUG_SESSION_STOP=1

function stickyFooter() {
	let footer = document.querySelector('#tracy-bs footer');
	footer.classList.toggle('tracy-footer--sticky', false); // to measure footer.offsetTop
	footer.classList.toggle('tracy-footer--sticky', footer.offsetHeight + footer.offsetTop - window.innerHeight - document.documentElement.scrollTop < 0);
}

let Tracy = window.Tracy = window.Tracy || {};
Tracy.BlueScreen = Tracy.BlueScreen || BlueScreen;
})();Nette\InvalidStateException: Cannot send header after HTTP headers have been sent (output started at /var/www/clients/client0/web7/web/vendor/tracy/tracy/src/Tracy/Debugger/DeferredContent.php:76). in /var/www/clients/client0/web7/web/vendor/nette/http/src/Http/Response.php:273
Stack trace:
#0 /var/www/clients/client0/web7/web/vendor/nette/http/src/Http/Response.php(84): Nette\Http\Response->checkHeaders()
#1 /var/www/clients/client0/web7/web/temp/cache/nette.configurator/Container_a4279b605b.php(2652): Nette\Http\Response->setHeader('...', '...')
#2 /var/www/clients/client0/web7/web/temp/cache/nette.configurator/Container_a4279b605b.php(2656): Container_a4279b605b->{closure}()
#3 /var/www/clients/client0/web7/web/vendor/nette/bootstrap/src/Bootstrap/Configurator.php(241): Container_a4279b605b->initialize()
#4 /var/www/clients/client0/web7/web/www/index.php(10): Nette\Bootstrap\Configurator->createContainer()
#5 {main}

(stored in /var/www/clients/client0/web7/web/log/exception--2024-04-19--12-33--48522ffb8d.html)

@dg
Copy link
Member

dg commented Apr 19, 2024

As I wrote, try to find out why the exit is not called https://github.com/nette/tracy/blob/master/src/Tracy/Debugger/Debugger.php#L259

@M4RtY
Copy link
Author

M4RtY commented Apr 19, 2024

Yes, thank you! As I have tried to step in to the code and dumped the exit, it is called, the output is true, so in this case I can presume the problem with headers is somewhere else.

Imho this can happen somewhere here $strategy->initialize();

If I am right - I have opened Container_{hash}.php file and there is initialize() method and there is a code:\

$response->setHeader('X-Powered-By', 'Nette Framework 3');
$response->setHeader('Content-Type', 'text/html; charset=utf-8');
$response->setHeader('X-Frame-Options', 'SAMEORIGIN');

And here it looks like it fails.

@dg dg closed this as completed Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants