+
Skip to content

@webext-core/messaging errors with No response when return value contains function #55

@lionelhorn

Description

@lionelhorn

First, many thanks to the contributors ! Nice project and utils 👍

I'm using a content script in main world context to dynamically extract "react props" from the whole dom tree for use in another content script not running in main world context.

In console logs the following abreviation stands for
MW: Main World
CS: Content Script

Messenger caller is in a CS without MW context

Failing: with error thrown but error message doesn't explain why No response

Error message just says

chunk-ALTBYIMW.js:80 Uncaught (in promise) Error: No response
    at Object.<anonymous> (chunk-ALTBYIMW.js:80:92)
    at Generator.next (<anonymous>)
    at fulfilled (chunk-ALTBYIMW.js:37:19)

The issue is that the return value object contains a function.

Example simplified code :

mainWorldMessenger.onMessage("test", (data) => {
  const props = [
    {
      "className": "ml-md",
      onClick: () => {
      }
    }
  ]

  const ret = {reactProps: props};
  log("return value will be", ret)

  return ret
});
image

Working: messenger func returns with value

mainWorldMessenger.onMessage("test", (data) => {
  const props = [
    {
      "className": "ml-md",
    }
  ]

  const ret = {reactProps: props};
  log("return value will be", ret)

  return ret
});
image

Solution

Return value can be sanitized.
An error message from @webext-core/messaging explaining why it doesn't return would be nice

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载