plasmo icon indicating copy to clipboard operation
plasmo copied to clipboard

[BUG] executeScript with async func

Open younes200 opened this issue 8 months ago • 0 comments

What happened?

Hi, I am trying to execute an asynchronous function in popup.tsx as shown by this simple example:


async function test () {
          return new Promise((resolve) =>
            resolve(["hello", "world"]),
          );
}

<button
  onClick={() => {
    chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
      const { id } = tabs[0];
      chrome.scripting.executeScript({
        target: { tabId: id },
        world: "MAIN",
        func: test
        args: [],
      });
    });
  }}>
  Async function call
</button>

Manifest permissions includes : activeTab, scripting.

The issue appears to be with using async with plasmo. It works fine when the function is not async, which implies that chrome.scripting.executeScript can handle asynchronous calls, but not when you use it with plasmo.

If anyone could provide some assistance with this issue, it would be greatly appreciated.

Version

Latest

What OS are you seeing the problem on?

MacOSX

What browsers are you seeing the problem on?

Chrome

Relevant log output

Exception : 

Uncaught ReferenceError: _func is not defined
    at func (<anonymous>:2:37)
    at <anonymous>:3:35

Generated coded :

(function func() {
    return _func.apply(this, arguments);
})()


### (OPTIONAL) Contribution

- [ ] I would like to fix this BUG via a PR

### Code of Conduct

- [X] I agree to follow this project's Code of Conduct
- [X] I checked the [current issues](https://github.com/PlasmoHQ/plasmo/issues?q=is%3Aopen+is%3Aissue+label%3Abug) for duplicate problems.

younes200 avatar Jun 22 '24 14:06 younes200