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

[BUG] executeScript with async func #1009

Open
younes200 opened this issue Jun 22, 2024 · 0 comments
Open

[BUG] executeScript with async func #1009

younes200 opened this issue Jun 22, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@younes200
Copy link

younes200 commented Jun 22, 2024

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 younes200 added the bug Something isn't working label Jun 22, 2024
@younes200 younes200 reopened this Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant