[Safari Extension Dev] Return from browser.scripting.executeScript is always null?

I'm using manifest v3 and working on a Safari extension. When I try to run a function within activeTab. I can not get the proper return from the the function. For example:

browser.scripting.executeScript({
		    target:{tabId:tab.id},
		    func:()=>'test',
		}).then(result=>{
		    console.log('result',result)
		})

Here the result is always null. Is it a bug?

Nothing wrong with permission settings because if I use files instead of func, the return value works properly.

  • Safari: Version 16.1 (18614.2.3.1.1)
  • macOS 13.0 Beta
  • Xcode: Version 14.0 beta 5

Thanks

Answered by Zijar in 768499022

I tested on Safari 17.0 and it works. The bug is fixed.

Did you find the answer? i have same problem

Can someone answer this?

Any solutions?

This is working for me with 16.4.1, at least when I run it with world: "MAIN".

Here is my working (chromium/safari cross-platform) code:

const stuff = await chrome.scripting.executeScript({
  target: { tabId: tab.id },
  func: (lang) => {
    const subs = window.mysubs[lang];
    const language = window.mylanguage;
    return {
      subs,
      language,
    };
  },
  args: [myLang],
  world: "MAIN",
});
/* safari doesn't return InjectionResults, it returns the values directly;*/
myData = stuff[0]?.result || stuff[0];
Accepted Answer

I tested on Safari 17.0 and it works. The bug is fixed.

[Safari Extension Dev] Return from browser.scripting.executeScript is always null?
 
 
Q