New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 661431 link

Starred by 2 users

Issue metadata

Status: WontFix
Owner: ----
Closed: Nov 2016
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Windows
Pri: 2
Type: Bug



Sign in to add a comment

sendMessage() communication chain is out of order

Reported by thd...@gmail.com, Nov 2 2016

Issue description

UserAgent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.28 Safari/537.36

Steps to reproduce the problem:
1. Load test.zip as an unpacked extension
2. Monitor the extension's background page Console tab
3. Go to any web page and monitor its Console as well
4. Click anywhere on the web page

What is the expected behavior?
After clicking the mouse, a communication is started between the content script (CS) and event page (EP) that goes like this: CS -> EP -> CS -> EP-> CS.

The console.log order should be like this:

1. Initiate communication with EP
2. Received initial message from CS; send message back
3. Got message from event page; send response
4. Got response from CS; send response to initial message
5. Got response from EP; communication is complete

What went wrong?
The console.log order is this:

1. Initiate communication with EP
2. Received initial message from CS; send message back
5. Got response from EP; communication is complete
3. Got message from event page; send response
4. Got response from CS; send response to initial message

Did this work before? N/A 

Does this work in other browsers? N/A

Chrome version: 55.0.2883.28  Channel: beta
OS Version: 6.1 (Windows 7, Windows Server 2008 R2)
Flash Version: Shockwave Flash 23.0 r0

Shouldn't #5 be logged after receiving the response from the #4 callback (eventPage.js line 13)? My gut feeling is the sendMessage() timeout period is too short, so you cannot have a sendReponse() inside a callback, but in this case why is the initial sendMessage() from the CS getting a callback response at all (i.e., #5 should never be logged).
 
test.zip
1.9 KB Download

Comment 1 by woxxom@gmail.com, Nov 2 2016

Your code incorrectly uses sendResponse inside an asynchronous callback of chrome.tabs.sendMessage.

As per documentation[1]: ALL chrome.* function callbacks are asynchronous.
As per documentation[2]: onMessage listener should "return true" in order to be able to use "sendResponse" in an async function later.

[1]: https://developer.chrome.com/extensions/overview#sync
[2]: https://developer.chrome.com/extensions/runtime#event-onMessage
Cc: sureshkumari@chromium.org
Components: Platform>Extensions
Labels: Needs-Feedback
unable to reproduce the issue on windows-7 using chrome stable version 54.0.2840.87, canary 56.0.2907.0
and reported Beta version 55.0.2883.28 with below steps
1.opened chrome
2.Loaded test.zip as an unpacked extension
3.Navigated to the the extension's background page Console tab 
4.Navigated to web page and clicked on it and not observed the console log
please find the attached screenshot for reference and let us know anything missed here to reproduce the issue.

Thanks.

661431.PNG
101 KB View Download

Comment 3 by thd...@gmail.com, Nov 7 2016

#2 I think the root cause is my using sendResponse inside a callback of chrome.tabs.sendMessage as mentioned in #1. Please close this.

Comment 4 by thd...@gmail.com, Nov 7 2016

With this said, what is considered the "best practice" way for a content script that is injected in all frames ("all_frames": true in manifest) to communicate to the top frame after a certain JS function is done executing in all the frames? It would be nice to have a serial communication option for this purpose.
Labels: -Needs-Feedback
Status: WontFix (was: Unconfirmed)
As per comment #3, closing this issue as won't fix.
Please raise a new bug, if still facing issue with chrome further.

Thanks..!!

Sign in to add a comment