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

DebugToolbar - too much recursion #1650

Closed
nowackipawel opened this issue Jan 3, 2019 · 7 comments
Closed

DebugToolbar - too much recursion #1650

nowackipawel opened this issue Jan 3, 2019 · 7 comments

Comments

@nowackipawel
Copy link
Contributor

nowackipawel commented Jan 3, 2019

I've noticed on some pages that there is no Debug Toolbar icon... i thought it is because of my CSP settings... but I think it is because:

I've noticed on some pages that there is no Debug Toolbar icon... i thought it is because of my CSP settings... but I think it is because:

FF:

dev.my-host.com:66:6
newXHR
https://dev.my-host.com/:66:6
newXHR
https://dev.my-host.com/:66:16
newXHR
https://dev.my-host.com/:66:16
newXHR
https://dev.my-host.com/:66:16
newXHR
https://dev.my-host.com/:66:16
newXHR
(... about 60 times X 2)

Irudium@Chromium:

2?debugbar:1 Uncaught RangeError: Maximum call stack size exceeded
    at new newXHR (?debugbar:1)
    at new newXHR (?debugbar:66)
    at new newXHR (?debugbar:66)
    at new newXHR (?debugbar:66)
    at new newXHR (?debugbar:66)
    at new newXHR (?debugbar:66)
    at new newXHR (?debugbar:66)
    at new newXHR (?debugbar:66)
    at new newXHR (?debugbar:66)
    at new newXHR (?debugbar:66)

I think my code is up to date:


// Track all AJAX requests           - LINE 62
var oldXHR = window.XMLHttpRequest;

function newXHR() {
	var realXHR = new oldXHR();    - LINE 66
	realXHR.addEventListener("readystatechange", function() {
		// Only success responses and URLs that do not contains "debugbar_time" are tracked
		if (realXHR.readyState === 4 && realXHR.status.toString()[0] === '2' && realXHR.responseURL.indexOf('debugbar_time') === -1) {
			var debugbarTime = realXHR.getResponseHeader('Debugbar-Time');
			if (debugbarTime) {
				var h2 = document.querySelector('#ci-history > h2');
				h2.innerHTML = 'History <small>You have new debug data.</small> <button onclick="loadDoc(' + debugbarTime + ')">Update</button>';
				var badge = document.querySelector('a[data-tab="ci-history"] > span > .badge');
				badge.className += ' active';
			}
		}
	}, false);
	return realXHR;
}

window.XMLHttpRequest = newXHR;        - LINE 82

in this case I don't use d() or anything like that, just wanna to see Debug Toolbar. There is some complex data passed to the view but nothing big :/.

@natanfelles
Copy link
Contributor

natanfelles commented Jan 6, 2019

Please, how can we reproduce it?

@nowackipawel
Copy link
Contributor Author

nowackipawel commented Jan 6, 2019

What do you need? :).
I've got only one action where there this issue occur. ... example json file from debugbar when the issue occurred (i cut out salt and other sensitive data; zip password is set to your nickname ).

debugbar_1546811372.json.zip

@nowackipawel
Copy link
Contributor Author

pls lemme know if you will need anything else :).
as for now i don't have more ideas what could be helpful for u.

@natanfelles
Copy link
Contributor

I refers to example codes. What has in the HTML? Has custom (not from debugbar) AJAX calls happening? Is this issue happening with other use cases, how? Are you sure that the returned AJAX, if any, is not returning the Content-Type Header as html? - if has html, the debugbar is appended, then the recursion will occurs.

@nowackipawel
Copy link
Contributor Author

Unfortunately there is no ajax call on this page at all. I am using ajax calls in the app widely but this route is free from ajax calls :(. That issue doesn't occur on pages where I am using ajax calls.

Html is here:
html-que-id.html.zip
password as was in the previous file.

Calls:

200
GET
1570
dev.ss.com
document
html
6.43 KB
20.71 KB
21 ms
200
GET
main.css?t=1546862966
dev.ss.com
stylesheet
css
216.68 KB
216.24 KB
1 ms
304
GET
jquery-3.3.1.min.js
dev.ss.com
script
js
cached
0 B
2 ms
304
GET
popper.min.js
dev.ss.com
script
js
cached
0 B
2 ms
304
GET
bootstrap.min.js
dev.ss.com
script
js
cached
0 B
3 ms
GET
css?family=Montserrat:400,800|Open+Sans:400,700&subset=latin-ext
fonts.googleapis.com
stylesheet
200
GET
/?debugbar
dev.ss.com
script
js
3.34 KB
3.05 KB
8 ms

I didn't see that issue on other routes, I've got defined around 40 of routes.

I could try to organize VPN access to this page if you have to check anything else (it is on my laptop). It is unfinished but I am not planing to change anything in next few days in its code in next couple of days. In case you'd like to see it please write me an email.

@natanfelles
Copy link
Contributor

natanfelles commented Jan 8, 2019

Yeah! Look at the HTML code. It has two </body>, then the debugbar code is replaced two times, and loaded two times. It has two <body> tags too.

The replacements are made here:

$script = PHP_EOL
. '<script type="text/javascript" {csp-script-nonce} id="debugbar_loader" '
. 'data-time="' . $time . '" '
. 'src="' . site_url() . '?debugbar"></script>'
. '<script type="text/javascript" {csp-script-nonce} id="debugbar_dynamic_script"></script>'
. '<style type="text/css" {csp-style-nonce} id="debugbar_dynamic_style"></style>'
. PHP_EOL;
if (strpos($response->getBody(), '</body>') !== false)
{
$response->setBody(
str_replace('</body>', $script . '</body>', $response->getBody())
);
return;
}

@nowackipawel
Copy link
Contributor Author

Woow. gr8.
My editor (php storm) changed tbody => body (weird). Ofc everything is working now.
Thank you for pointing this out...:D

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

3 participants