为什么承诺未定义? chrome.tabs.query(),然后();

时间:2018-04-10 13:12:56

标签: google-chrome-extension es6-promise

它是否假设在每个内置的chrome函数中定义?

  

未捕获的TypeError:无法读取属性'然后'在popup.js中未定义:23

var requestCurrentTabId = {
  active:true,
  windowType:"normal",
  currentWindow: true
};

function getCurrentTab(chromeOpenedTabsList){
  window.currentTabId = chromeOpenedTabsList[0].id;

  //Connect to the content_script messaging port
  //on the current opened page, the extension user is visiting.
  var messagePassingPort = chrome.tabs.connect(currentTabId, {name: "content_script_port"});

  //Inject selection listener into Chrome PDF viewer
  //after opening this popup.


  console.log("Current tab:" + window.currentTabId);
}
//getCurrentTab - is a callback


chrome.tabs.query(requestCurrentTabId, getCurrentTab).then(console.log("Current tab2:" + window.currentTabId));

0 个答案:

没有答案