chrome.runtime.sendMessage() turns Maps into empty Objects.
Reported by
rbrownw...@gmail.com,
Apr 10 2016
|
|||||
Issue descriptionChrome Version : 51.0.2700.0 dev-m Also tested Canary (51.0.2704.0 canary (64-bit)) What steps will reproduce the problem? (1) Use chrome.runtime.sendMessage() in an extension content script to send a Map (or an Object containig a Map). (2) Receive message in an extension background script. What is the expected result? The received message should still be a Map/ contain the Map(s). What happens instead? All Maps in the message have been replaced with empty Objects. Please provide any additional information below. Attach a screenshot if possible. Windows 10 See https://github.com/rbrownwsws/chromemapbug for a small extension demonstrating this behaviour. Open a developer console for the background script and another for any random webpage. Note the message sent is not the same as the one received. N.B. This can be worked around by converting the Map into an Array before sending it then turning it back on the other side.
,
Apr 11 2016
I'm not getting that failed to load resource stuff. I'm guessing it's coming from something unrelated. A bit clearer steps: You'll need to have two sets of Developer Tools Consoles open: - One for the content script - Go to random webpage then "Hamburger Menu->More Tools->Developer Tools" (as you did in "Screen Shot 1.png"). - One for the background script - Go to chrome://extensions/ and click "Map Bug->Inspect views: background page". See Attached "debug_background-script.png"). Clear both consoles to get rid of extra messages. Reload the random webpage you chose so the extension's content script will re-run. You should be see something like what is shown in the Attached "map_bug.png" Note that message.testMap has mysteriously gone from a Map to an empty Object in transit between the content script and the background script. This does not seem to affect Arrays and Objects as they arrive unchanged. You got the error in your second screenshot because the message parameter is not optional (sorry I didn't bother to put the whole method signature in the bug description). This is the documentation for the method I have been using: https://developer.chrome.com/extensions/runtime#method-sendMessage You can see how the extension uses it by looking inside content_script.js
,
Apr 11 2016
Thank you for providing more feedback. Adding requester "ranjitkan@chromium.org" for another review and adding "Needs-Review" label for tracking. For more details visit https://sites.google.com/a/chromium.org/dev/issue-tracking/autotriage - Your friendly Sheriffbot
,
Apr 11 2016
I did a little digging and I found where the problem is happening: https://code.google.com/p/chromium/codesearch#chromium/src/extensions/renderer/resources/messaging.js&q=chrome.runtime.sendMessage&sq=package:chromium&dr=C&l=53 src/extensions/renderer/resources/messaging.js: Line 53: msg = $JSON.stringify(msg); "msg" starts out as the message passed to chrome.runtime.sendMessage(...). In the JSON string returned by $JSON.stringify(...) all Maps are replaced with "{}". Although I have not tested it I guess that there will be similar problems sending messages using other types that are not trivial to serialise into JSON.
,
Apr 25 2016
This time when I load extension I am not getting any messages in the Console. Attached screen shot for the same. Request to please take a look into it.
,
Apr 25 2016
It looks like content scripts are not run against chrome://<xyz> pages. Try something like https://www.wikipedia.org/ as the page you open the normal developer tools on. If that is not the problem I'm not sure why it is not working. It looks like someone has updated the documentation at: https://developer.chrome.com/extensions/runtime#method-sendMessage so it now says the message must be JSON-ifiable which should help prevent future confusion. I guess this could be considered solved as just a documentation issue if this was the desired behaviour. The only thing I would add is that it would be nice for there to be some kind of warning/error in the console to indicate parts of the message could not be serialised to JSON. At the moment there is only an error if $JSON.stringify(msg); returns "undefined". A comment just below "msg = $JSON.stringify(msg);" seems to suggest that chrome.runtime.sendMessage should have performed some validation on the message already before allowing it to get this far but these messages with Maps in them have somehow slipped through. Maybe there is a problem with that earlier validation? See the link in Comment 4 for the full comment.
,
Apr 25 2016
Thank you for providing more feedback. Adding requester "ranjitkan@chromium.org" for another review and adding "Needs-Review" label for tracking. For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
,
Apr 29 2016
Sounds like the docs fix works out. |
|||||
►
Sign in to add a comment |
|||||
Comment 1 by ranjitkan@chromium.org
, Apr 11 2016Labels: Needs-Feedback
117 KB
117 KB View Download
113 KB
113 KB View Download