chrome.tabs.executeScript - 如何让脚本返回值?

The*_*chu 3 javascript return google-chrome-extension

我正在使用chrome.tabs.executeScript将脚本注入到选项卡中.它的最后一个参数是一个将被调用的回调函数The result of the script in every injected frame..如何让我的脚本返回结果?我尝试在js的末尾添加一个简单的return语句,但没有返回任何内容.

Bea*_*ist 5

正如RobW纠正我的那样,函数不是必需的,只要确保所需的数据是最后一个表达式,当然这是JSON可序列化的.

chrome.tabs.executeScript(tabId,
  {code:"document.charset"},
  function(results){
     // results[0] will now contain the charset for the page in question
});
Run Code Online (Sandbox Code Playgroud)