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

AJAX request headers are lost when using window.fetch #323

Closed
zdhr opened this issue Oct 6, 2018 · 3 comments
Closed

AJAX request headers are lost when using window.fetch #323

zdhr opened this issue Oct 6, 2018 · 3 comments

Comments

@zdhr
Copy link

@zdhr zdhr commented Oct 6, 2018

Version: 2.5.3

Bug Description

When Tracy modifies window.fetch in captureAjax, it losses original header information.

I suppose it's because options.headers in fetch isn't a standart object.

This will show empty object in dev console (chrome), even if some headers are set:

console.log(options.headers);

But this will print out headers names:

for (let key of options.headers.keys()) {
	console.log(key);
}

Steps To Reproduce

Send simple fetch request with some additional headers set, eg. X-Requested-With: XMLHttpRequest.

Here is simple code snippet you can run from browser dev console. It might 404, but that doesn't matter. Run the code and then look at the request in dev tools network tab.

When Tracy is running, there will be only one header set by Tracy.
When Tracy is not running, there will headers originally passed to fetch.

function ajax(url) {
	const fetchOptions = {
		credentials: 'include',
		headers: new Headers({
			'X-Requested-With': 'XMLHttpRequest',
		}),
	};

	fetch(new Request(url, fetchOptions));
}

ajax('127.0.0.1');

Expected Behavior

Headers won't disappear from window.fetch requests.

At least please disable captureAjax for window.fetch till it's fixed, Because right now it's useless anyway. It's used mostly/only for ajax requests, but it will strip away the information which tells the server this is ajax request.

@zdhr zdhr changed the title AJAX request headers are lost in when using window.fetch AJAX request headers are lost when using window.fetch Oct 6, 2018
@zdhr

This comment has been minimized.

Copy link
Author

@zdhr zdhr commented Feb 14, 2019

I did some more digging around. It's only broken when you call fetch with Request object as its single parameter eg. fetch(new Request({...})).

If you call fetch with two parameters fetch(url, options), then it works fine.

@dg

This comment has been minimized.

Copy link
Member

@dg dg commented Feb 15, 2019

//cc @jiripudil

@dg dg closed this in f3ef8e1 Feb 15, 2019
@dg

This comment has been minimized.

Copy link
Member

@dg dg commented Feb 15, 2019

Thanks for great report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.