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

Uint8Array gets converted into object when using with sendMessage/onMessage #643

Closed
sharma66mahesh opened this issue Jun 24, 2024 · 1 comment

Comments

@sharma66mahesh
Copy link

I send an object with the following code from the UI side as follows:

const result = await Browser.runtime.sendMessage({ action: 'GET_UINT8ARRAY' });
console.log(result)

Then I process this request on my background script and try to send back an uint8Array with the following code:

Browser.runtime.onMessage((payload) => {
  if(payload.action == 'GET_UINT8ARRAY') {
    return new Promise(resolve => resolve({ uint8Arr: new Uint8Array([1,2,3]) }  ))
  } 
})

Expected result:

{
  uint8Arr: [1, 2, 3]
}

Actual result received:

{ 
  uint8Arr: {
    0: 1,
    1: 2,
    2: 3
  }
}
@Rob--W
Copy link
Member

Rob--W commented Jun 24, 2024

This is not an issue with the polyfill but with Chrome. Chrome has a serialization mechanism that does a bit more than JSON serialization, but is less capable than structured cloning.

Support for that is tracked at https://issues.chromium.org/issues/40321352

@Rob--W Rob--W closed this as completed Jul 4, 2024
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

2 participants