[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

Add a Comment

Accepted Reply

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

Replies

Did you find the answer? i have same problem

  • No, it's still the case and no one replied :(

Add a Comment

Any solutions?

  • Unfortunately no. Although calling browser.scripting.executeScript with files works properly.

Add a Comment

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];
  • Mine is Version 16.4 (18615.1.26.110.1). Are you on a beta version?

Add a Comment

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