sending the same XMLHttpRequest twice

1,402 views
Skip to first unread message

Richard Bernstein

unread,
Dec 14, 2018, 10:13:58 PM12/14/18
to Chromium Extensions
My Extension is sending the same send message twice. I am sure that my code that sends it is not running twice. The reason I know it is the browser sending it twice is that I ran Wireshark on it and the browser is doing the damage. Here is my function from the background script that is sending it:

function send_to_logger_survey(request, sender, sendResponse)
{
var myArray=[];
var jsonResponse2;

myArray.push(email);
myArray.push(request.values); //contains chosen values
var json = JSON.stringify(myArray);
var url=szHost;
url=url.concat('/Subit_backend/logger_survey');
var xhr = new XMLHttpRequest();
xhr.onerror = function() { alert('error'); };
xhr.open('POST', url, true);
xhr.setRequestHeader("Content-type", "application/json")
xhr.setRequestHeader("X-Requested-With",'xmlhttprequest');
xhr.setRequestHeader("Access-Control-Allow-Origin", "*");

xhr.onload = function (){
if((xhr.status === 200)&&(xhr.readyState===4)) {
var jsonResponse2 = JSON.parse(xhr.responseText);
sendResponse({task: jsonResponse2});
return true; //The sendResponse callback is only valid if used synchronously, or if the event handler returns true to indicate that it will respond asynchronously.
}

};

xhr.send(json);
}

I have run it under the debugger and can see that xhr.send() is only running once. BTW, the transmission being sent twice is almost identical, juts off by a few bytes, but the payload is the same. Do you have any idea what is going on and perhaps a hint of where to look? I just want to send the packet once. The server is responding with code 200 twice too!

Richard Bernstein

unread,
Dec 15, 2018, 12:06:33 AM12/15/18
to Chromium Extensions
This is what calls send_to_logger_survey in the background task

if (request.task =="log_results_survey"){
send_to_logger_survey(request, sender, sendResponse);
};

The log_results_survey is a message being sent from the content script.

PhistucK

unread,
Dec 15, 2018, 7:12:31 AM12/15/18
to Richard Bernstein, Chromium-extensions
One little unrelated note -
> return true; //The sendResponse callback is only valid if used synchronously, or if the event handler returns true to indicate that it will respond asynchronously.   
This has no effect in your code, because you put it within the XMLHttpRequest.prototype.onload function. You need to put return true from the original handler/listener of the onMessage event.

Regarding the issue itself, what do you see in the Network panel of the Developer Tools for the background page?
Do you actually see two requests?
Is there a service worker at play?

Regarding the few-byte-difference, it might be crucial, what exactly is the difference?
Perhaps this is the cross-origin pre-flight request (an OPTIONS request rather than a POST request)?
Did you add the relevant host to the manifest permissions key?


☆PhistucK


--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at https://groups.google.com/a/chromium.org/group/chromium-extensions/.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/6b7f955f-4b26-4876-954b-60cb8e152f44%40chromium.org.
For more options, visit https://groups.google.com/a/chromium.org/d/optout.

Richard Bernstein

unread,
Dec 15, 2018, 8:58:01 AM12/15/18
to Chromium Extensions
PhiStuck, I moved the return true to after the send(json). same result. Is it possible to post images up here? Anyway, I ran wireshark on the client. This is what I get:

HTTP 1304 POST /subcrud/Subit_backend/logger_survey HTTP 1.1 (application/json)
TLSv1.2 206 Server Hello, Change Cipher Spec, Finished
TLSv1.2 105 Change Cipher Spec, Finished
HTTP 1304 POST /subcrud/Subit_backend/logger_survey HTTP 1.1 (application/json)
TCP 60 443 -> 49681 [ACK] Seq=153 Ack=1851 Win 30528 Len=0
TCP 60 443 -> 49681 [ACK] Seq=153 Ack=1851 Win 30528 Len=0
HTTP 687 HTTP/1.1 200 OK (application/json)

see the two POSTS?

On the Network tab of the Chrome debugger I am only seeing one request from the browser. This is the request header:
POST /sub_crud/Subit_backend/logger_survey HTTP/1.1
Host: www.antiation.com
Connection: keep-alive
Content-Length: 649
Pragma: no-cache
Cache-Control: no-cache
Access-Control-Allow-Origin: *
Origin: chrome-extension://jgnodlhfmhghjhbkkkaa
X-Requested-With: xmlhttprequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36
Content-type: application/json
Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Cookie: XDEBUG_SESSION=XDEBUG_ECLIPSE; cisession=ic10vmohovjquoh5jubk7ki6ul5d9qap

On the permissions question in manifest, I already have that. Could the Cipher change be causing it?


PhistucK

unread,
Dec 15, 2018, 1:07:05 PM12/15/18
to Richard Bernstein, Chromium-extensions
I do not know. If you run exact same request code from a website (try cross-origin and try same-origin, using the Developer Tools), does it behave differently?

☆PhistucK


--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at https://groups.google.com/a/chromium.org/group/chromium-extensions/.

Richard Bernstein

unread,
Dec 17, 2018, 9:08:06 AM12/17/18
to Chromium Extensions
I did a little test where I pushed get(Time) onto the end of my payload before sending it with send().  I then ran a test with Wireshark again. Here is what I see in the two:

from the first POST    value: 1545054382811
from the second POST   value: 1545054382812

Notice that they are just one (is that ms?) from each other? Way too fast for a human to do! So it is perhaps it is a bug in Chrome? You can see the code above. What am I doing wrong?

PhistucK

unread,
Dec 17, 2018, 9:23:21 AM12/17/18
to Richard Bernstein, Chromium Extensions
If you put a breakpoint (maybe a conditional breakpoint that only console.log a message) where you add that value, does it break/log twice?

My suggestion to do it in a regular website still stands.

☆PhistucK


--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at https://groups.google.com/a/chromium.org/group/chromium-extensions/.

Richard Bernstein

unread,
Dec 17, 2018, 9:49:15 AM12/17/18
to Chromium Extensions
Thanks again. I have NO IDEA how to send the same message from the Chrome debugger itself, but I am willing to try. Do the doc's for the debugger say how to do that? Also, I did get this suggestion from bitnami:

"You could try disabling PageSpeed and OPCache. Let us know if that solves the issue!"

I disabled OPCache without a change. I don't know where Pagespeed is. I couldn't find it in the php.ini file.

I have found some mention of a Chrome bug where a second port (at port n-1) sends a second buffer, but it is blank . In my case I have a second port opening at port n-1 but the 2nd buffer is not blank. https://productforums.google.com/forum/#...-gfRJLCCjg

Richard Bernstein

unread,
Dec 17, 2018, 9:50:31 AM12/17/18
to Chromium Extensions
Oh yeah, I did put a breakpoint on the send(json) line, earlier. It only breaks one time.

Richard Bernstein

unread,
Dec 17, 2018, 9:53:23 AM12/17/18
to Chromium Extensions
Bad link for the "bug". Here is a better one. https://productforums.google.com/forum/#!topic/chrome/Q-gfRJLCCjg

There seems to be many complaints about this second port opening too.

PhistucK

unread,
Dec 17, 2018, 11:22:22 AM12/17/18
to Richard Bernstein, Chromium Extensions
Forget the message, initiate the HTTP request from another website by running (copying and pasting) the code from your message handler in the console of the Developer Tools.
No specific documentation, as the console simply runs whatever you enter in it, that is its job (and showing logs).

If you do not see the second request in the network panel of the Developer Tools, then perhaps it is initiated from a different context (a content script in a tab, rather than a script in the background page, for example).
Can you share your manifest?


☆PhistucK


--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at https://groups.google.com/a/chromium.org/group/chromium-extensions/.

Richard Bernstein

unread,
Dec 20, 2018, 4:17:52 PM12/20/18
to Chromium Extensions, rich...@gmail.com
I was actually under the impression that I could ONLY initiate it from the background task! So I am pretty positive that is the only place I am doing a send(). One more odd thing. I ran Wireshark on the PC while I am debugging under Chrome Dev Tools. Wireshark sees two buffers, but Chrome Dev tools only sees one. These are the headers to the send():

xhr.open('POST', url, true);
    xhr.setRequestHeader("Content-type", "application/json")
    xhr.setRequestHeader("X-Requested-With",'xmlhttprequest');
xhr.setRequestHeader("Access-Control-Allow-Origin", "*");

I am at a loss. Is there anyway that I could put a breakpoint in the send() command or somewhere deeper? I already put a breakpoint on the send() itself and it is only being triggered once in my code. 

On Monday, December 17, 2018 at 11:22:22 AM UTC-5, PhistucK wrote:
Forget the message, initiate the HTTP request from another website by running (copying and pasting) the code from your message handler in the console of the Developer Tools.
No specific documentation, as the console simply runs whatever you enter in it, that is its job (and showing logs).

If you do not see the second request in the network panel of the Developer Tools, then perhaps it is initiated from a different context (a content script in a tab, rather than a script in the background page, for example).
Can you share your manifest?


☆PhistucK


On Mon, Dec 17, 2018 at 4:49 PM Richard Bernstein <rich...@gmail.com> wrote:
Thanks again. I have NO IDEA how to send the same message from the Chrome debugger itself, but I am willing to try. Do the doc's for the debugger say how to do that?  Also, I did get this suggestion from bitnami:

"You could try disabling PageSpeed and OPCache. Let us know if that solves the issue!"

I disabled OPCache without a change. I don't know where Pagespeed is. I couldn't find it in the php.ini file.

I have found some mention of a Chrome bug where a second port (at port n-1) sends a second buffer, but it is blank . In my case I have a second port opening at port n-1 but the 2nd buffer is  not blank. https://productforums.google.com/forum/#...-gfRJLCCjg



--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.

PhistucK

unread,
Dec 20, 2018, 6:08:34 PM12/20/18
to Richard Bernstein, Chromium Extensions
I think this should be moved to crbug.com. Just create an issue there and a Chrome engineer will investigate. It would help if you attached a sample extension that reproduces the problem to the created issue.

Thank you.

☆PhistucK


On Thu, Dec 20, 2018 at 11:17 PM Richard Bernstein <rich...@gmail.com> wrote:
I was actually under the impression that I could ONLY initiate it from the background task! So I am pretty positive that is the only place I am doing a send(). One more odd thing. I ran Wireshark on the PC while I am debugging under Chrome Dev Tools. Wireshark sees two buffers, but Chrome Dev tools only sees one. These are the headers to the send():

xhr.open('POST', url, true);
    xhr.setRequestHeader("Content-type", "application/json")
    xhr.setRequestHeader("X-Requested-With",'xmlhttprequest');
xhr.setRequestHeader("Access-Control-Allow-Origin", "*");

I am at a loss. Is there anyway that I could put a breakpoint in the send() command or somewhere deeper? I already put a breakpoint on the send() itself and it is only being triggered once in my code. 

On Monday, December 17, 2018 at 11:22:22 AM UTC-5, PhistucK wrote:
Forget the message, initiate the HTTP request from another website by running (copying and pasting) the code from your message handler in the console of the Developer Tools.
No specific documentation, as the console simply runs whatever you enter in it, that is its job (and showing logs).

If you do not see the second request in the network panel of the Developer Tools, then perhaps it is initiated from a different context (a content script in a tab, rather than a script in the background page, for example).
Can you share your manifest?


☆PhistucK


On Mon, Dec 17, 2018 at 4:49 PM Richard Bernstein <rich...@gmail.com> wrote:
Thanks again. I have NO IDEA how to send the same message from the Chrome debugger itself, but I am willing to try. Do the doc's for the debugger say how to do that?  Also, I did get this suggestion from bitnami:

"You could try disabling PageSpeed and OPCache. Let us know if that solves the issue!"

I disabled OPCache without a change. I don't know where Pagespeed is. I couldn't find it in the php.ini file.

I have found some mention of a Chrome bug where a second port (at port n-1) sends a second buffer, but it is blank . In my case I have a second port opening at port n-1 but the 2nd buffer is  not blank. https://productforums.google.com/forum/#...-gfRJLCCjg



--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.

--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.

JT

unread,
Dec 21, 2018, 4:00:04 AM12/21/18
to Chromium Extensions, rich...@gmail.com
Hi Richard, I just wanted to add that I have seen this issue "in the wild" from a few of my extension's users from time to time, and I have to get them to restart chrome or reinstall my extension because they can spam my service with sometimes up to 8 duplicate requets.  My hunch is that something is malfunctioning withing the chrome extension messaging system.  Does your xhr request get fired off down the line from the extension api messaging system? 


On Friday, December 21, 2018 at 12:08:34 AM UTC+1, PhistucK wrote:
I think this should be moved to crbug.com. Just create an issue there and a Chrome engineer will investigate. It would help if you attached a sample extension that reproduces the problem to the created issue.

Thank you.

☆PhistucK


On Thu, Dec 20, 2018 at 11:17 PM Richard Bernstein <rich...@gmail.com> wrote:
I was actually under the impression that I could ONLY initiate it from the background task! So I am pretty positive that is the only place I am doing a send(). One more odd thing. I ran Wireshark on the PC while I am debugging under Chrome Dev Tools. Wireshark sees two buffers, but Chrome Dev tools only sees one. These are the headers to the send():

xhr.open('POST', url, true);
    xhr.setRequestHeader("Content-type", "application/json")
    xhr.setRequestHeader("X-Requested-With",'xmlhttprequest');
xhr.setRequestHeader("Access-Control-Allow-Origin", "*");

I am at a loss. Is there anyway that I could put a breakpoint in the send() command or somewhere deeper? I already put a breakpoint on the send() itself and it is only being triggered once in my code. 

On Monday, December 17, 2018 at 11:22:22 AM UTC-5, PhistucK wrote:
Forget the message, initiate the HTTP request from another website by running (copying and pasting) the code from your message handler in the console of the Developer Tools.
No specific documentation, as the console simply runs whatever you enter in it, that is its job (and showing logs).

If you do not see the second request in the network panel of the Developer Tools, then perhaps it is initiated from a different context (a content script in a tab, rather than a script in the background page, for example).
Can you share your manifest?


☆PhistucK


On Mon, Dec 17, 2018 at 4:49 PM Richard Bernstein <rich...@gmail.com> wrote:
Thanks again. I have NO IDEA how to send the same message from the Chrome debugger itself, but I am willing to try. Do the doc's for the debugger say how to do that?  Also, I did get this suggestion from bitnami:

"You could try disabling PageSpeed and OPCache. Let us know if that solves the issue!"

I disabled OPCache without a change. I don't know where Pagespeed is. I couldn't find it in the php.ini file.

I have found some mention of a Chrome bug where a second port (at port n-1) sends a second buffer, but it is blank . In my case I have a second port opening at port n-1 but the 2nd buffer is  not blank. https://productforums.google.com/forum/#...-gfRJLCCjg



--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.

--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.
Message has been deleted
Message has been deleted

Richard Bernstein

unread,
Dec 28, 2018, 4:21:51 PM12/28/18
to Chromium Extensions
Yes. It is fired by a child popup messaging the background task. When the parent popup sends a message to the background, and then the background sends it fine. I created an application level work around for now.
Reply all
Reply to author
Forward
0 new messages