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

e is not defined when use executeAsyncFunction #30

Open
matamune94 opened this issue Feb 21, 2021 · 1 comment
Open

e is not defined when use executeAsyncFunction #30

matamune94 opened this issue Feb 21, 2021 · 1 comment

Comments

@matamune94
Copy link

matamune94 commented Feb 21, 2021

I make error :

Error: Error thrown in execution script: e is not defined.
Stack: ReferenceError: e is not defined
    at <anonymous>:4:44
    at <anonymous>:4:76
    at <anonymous>:20:3
    at Object.chrome.tabs.executeAsyncFunction

my code:

      try {
        const scriptToExecute = async function() {
          return 'hi'
        }
        const results = await chrome.tabs.executeAsyncFunction(window.tabs[0].id, scriptToExecute)
      } catch (err) {
        console.log(err)
      }

Any have idea ?

@b5414
Copy link

b5414 commented Feb 24, 2021

@matamune94 try it:

(async()=>{
	const obj = {};

	obj.code = async()=>{
		await new Promise((r)=>setTimeout(r, 250)); // not important line
		return ['one', 'two'];
	};

	const w = await chrome.windows.create({url: 'https://google.com'});
	console.log(w);

	await new Promise((r)=>setTimeout(r, 1000)); // sometimes - important line
	try{
		const r = await chrome.tabs.executeAsyncFunction(w.tabs[0].id, obj);
		console.log(r);
	}catch(e){
		console.log(e);
	}
})();

also, make sure about permissions and the order of scripts:

"permissions": ["storage", "*://www.google.com/*", "tabs"],
"background": {"scripts": ["libs/cea.js", "libs/cea-eaf.js", "js/background.js"]},

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