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

Quasar BEX v3 postMessage payload format #9405

Closed
thomas66777 opened this issue May 24, 2021 · 2 comments
Closed

Quasar BEX v3 postMessage payload format #9405

thomas66777 opened this issue May 24, 2021 · 2 comments
Assignees

Comments

@thomas66777
Copy link

I am trying to setup a simple window eventListener to go from webpage to extension. I realize that this logic for this has been abstracted inside the auto-generated file bex/content/window-event-listener.js

export const listenForWindowEvents = (bridge, type) => {
  // Listen for any events from the web page and transmit to the BEX bridge.
  window.addEventListener('message', payload => {
...
    /**** payload.data is like an object right here ****/
    if (payload.data.from !== void 0 && payload.data.from === type) {

      /**** payload.data is like an array right here ****/
      const eventData = payload.data[0],
        bridgeEvents = bridge.getEvents()

      for (let event in bridgeEvents) {
        if (event === eventData.event) {
          bridgeEvents[event](eventData.payload)
        }
      }
    }
...
}

The problem is that payload.data is being used both like an Array and an Object. It requires both payload.data.from and payload.data[0] to work. I got it to work by setting up my webpage like this:

var payload = {
    target: 'toExtension',
    from: 'bex-content-script',
    sender: 'localhost',
    0: {event:'bridge.myevent', payload:{x:'y'}},
}
window.postMessage(payload, "*");

I realize this is probably not the way I am supposed to setup my payload and was wondering if I am missing something or if window-event-listener.js is meant to have a different property for payload data. Thank you

@rstoenescu
Copy link
Member

Fix will be available through q/app-webpack v3.4.0

var payload = {
    target: 'toExtension',
    from: 'bex-content-script',
    sender: 'localhost',
    event:'bridge.myevent',
    payload: {x:'y'}
}

@rstoenescu
Copy link
Member

I now realize that the initial code was correct. The payload is a MessageEvent and it is an Object with number keys and from key too. It wasn't a mistake. Reverting changes as it broke communication completely.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants