Closed Bug 796917 Opened 12 years ago Closed 12 years ago

wrong serialization in postMessage between iframe and content script

Categories

(Add-on SDK Graveyard :: General, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: thomas, Assigned: evold)

Details

Attachments

(2 files, 1 obsolete file)

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1
Build ID: 2012090600
SDK 1.10

Communication between an iframe and the content script of the outer page has a problem with the serialization of messages when using window.postMessage

I attached an example addon with the following two ways communication:

iframe -> outer page content script

send message: {
  first: "a string",
  second: ["an", "array"],
  third: {an: 'object'}
}

received message: {
  "first":"a string",
  "second": {"0":"an","1":"array"},
  "third":{"an":"object"}
}

-> array is transformed into object

outer page content script -> iframe
(reply to first message with msg.source.postMessage())

send message: {
  first: "a string",
  second: ["an", "array"],
  third: {an: 'object'}
}

received message: "[object Object]"

-> object is not serialized at all


When changing:

window.addEventListener (outer)
parent.postMessage (iframe)

to:

document.defaultView.addEventListener (outer)
parent.document.defaultView.postMessage (iframe)

-> same results as above.
Alex, if you get a chance, could you take a look at this?
s/Alex/Erik/
Flags: needinfo?(evold)
Whiteboard: [triage:followup]
Above result also verified with:

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20100101 Firefox/16.0
Build ID: 2012101000
SDK 1.11rc1
Thanks for the report!

I've created a test out of the example, at https://github.com/erikvold/jetpack-sdk/compare/796917

This does appear to be an issue with the sdk.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Flags: needinfo?(evold)
OS: Linux → All
Hardware: x86_64 → All
Assignee: nobody → evold
It looks like this has been an issue at least since 2011-07-20, probably never worked.
Attachment #677668 - Flags: review?(rFobic)
Comment on attachment 677669 [details]
Pointer to Github pull request: https://github.com/mozilla/addon-sdk/pull/647#attch-to-bugzilla

Okay, that wasn't even close to the attachment I clicked on to mark as obsolete, Bugzilla...
Attachment #677669 - Attachment is obsolete: true
Comment on attachment 677668 [details]
Pointer to Github pull request: https://github.com/mozilla/addon-sdk/pull/647

Comment about function was just a suggestion so I'll leave it up to you. Also I think conten-proxy.js has no access to modules so probably it's not worth it.
Attachment #677668 - Flags: review?(rFobic) → review+
Commits pushed to master at https://github.com/mozilla/addon-sdk

https://github.com/mozilla/addon-sdk/commit/aa2d116b1dc52464263b5c8fc2cb152614aec644
adding test for bug 796917 using postMessage to an iframe from a content script does not serialize data

https://github.com/mozilla/addon-sdk/commit/2f4f95b8f0a6c504ce17f07694b63d56aa09a8b8
Merge pull request #647 from erikvold/796917

fix bug 796917 using postMessage to an iframe from a content script does not serialize data r=@gozala
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Commit pushed to stabilization at https://github.com/mozilla/addon-sdk

https://github.com/mozilla/addon-sdk/commit/1b7692037f8c3cc98438351aa351bf5d394eaadd
adding test for bug 796917 using postMessage to an iframe from a content script does not serialize data
(cherry picked from commit aa2d116b1dc52464263b5c8fc2cb152614aec644)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: