本文介绍了无法让 Edge 在我的 WebExtension 中返回承诺的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 browser.tabs.create() 从我的 background.js WebExtension 创建一个新选项卡,如下所示:

createTab: function () {var newTab = browser.tabs.create({ url: someUrl });newTab.then(onCreated, onError);}

新标签页在浏览器中创建,但是当到达最后一行时,抛出一个错误:

SCRIPT5007:无法获取未定义或空引用的属性then"

Locals 窗口显示 newTabundefined.

我在这里做错了什么?我认为 .create() 会立即返回一个 Promise.我知道 create() 是一个异步函数 - 但我的调用函数不需要异步,是吗?

任何帮助将不胜感激.

解决方案

我最终阅读了

看起来很确定;现在我只需要一个使用回调的例子......

I am trying to create a new tab using browser.tabs.create() from my background.js WebExtension as shown here:

createTab: function () {
    var newTab = browser.tabs.create({ url: someUrl });
    newTab.then(onCreated, onError);
}

The new tab creates in the browser, but when the last line is reached, an error is thrown:

The Locals window shows newTab is undefined.

What am I doing wrong here? I thought that .create() would immediately return a Promise. I know create() is an asynchronous function - but my calling function doesn't need to by async, does it?

Any help would be appreciated.

解决方案

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...

这篇关于无法让 Edge 在我的 WebExtension 中返回承诺的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-16 22:51
查看更多