Can't get Edge to Return a Promise in my WebExtension

二次信任 提交于 2019-12-06 08:10:59

I ended up reading the Microsoft documentation (who knew?) and came across this little gem:

Seems pretty definitive; now I just need an example of using callbacks for it instead...

As Scott Baker already mentioned, Microsoft Edge extension APIs sadly don't support promises.

So you could refer to this MDN example on how to use callbacks:

browser.windows.onCreated.addListener((tab) => {
  console.log("New tab: " + tab.id);
});

Or even better: Provide the callback directly as second parameter to the create function:

var newTab = browser.tabs.create({ url: someUrl }, (tab) => {
  console.log("New window: " + window.id);
});

See the chrome docs (seems to apply for Edge, too): https://developer.chrome.com/extensions/tabs#method-create

Please note: You can achieve the same, if you're aiming for a new window (instead of a new tab) with windows.create(object createData, function callback)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!