Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js typescript中边缘web扩展API browser.runtime.*的browser.d.ts依赖项_Node.js_Typescript_Google Chrome Extension_Typescript Typings_Microsoft Edge Extension - Fatal编程技术网

Node.js typescript中边缘web扩展API browser.runtime.*的browser.d.ts依赖项

Node.js typescript中边缘web扩展API browser.runtime.*的browser.d.ts依赖项,node.js,typescript,google-chrome-extension,typescript-typings,microsoft-edge-extension,Node.js,Typescript,Google Chrome Extension,Typescript Typings,Microsoft Edge Extension,对于使用typescript开发的chrome扩展,我们需要在typings文件夹中创建一个名为chrome.d.ts的定义文件,用于访问诸如chrome.runtime.*或chrome.tabs.*等web扩展API 对于在typescript中开发的边缘扩展,我们需要typings文件夹中名为browser.d.ts的定义文件,用于访问诸如browser.runtime之类的web扩展API。* 如何使用节点包管理器(npm)下载此依赖项。 我在我的background.ts文件中添加了对

对于使用typescript开发的chrome扩展,我们需要在typings文件夹中创建一个名为chrome.d.ts的定义文件,用于访问诸如chrome.runtime.*或chrome.tabs.*等web扩展API

对于在typescript中开发的边缘扩展,我们需要typings文件夹中名为browser.d.ts的定义文件,用于访问诸如browser.runtime之类的web扩展API。*

如何使用节点包管理器(npm)下载此依赖项。 我在我的background.ts文件中添加了对该文件的引用,扩展名如下:


///reference path=“typings/browser/browser.d.ts”

更新:

Firefox的浏览器API及其浏览器polyfill库提供打字功能

  • Firefox打字:
  • 浏览器多边形填充的键入:
不幸的是,Edge的浏览器API与Firefox的不同。Edge使用回调,而Firefox使用承诺。这可能会改变,也可能不会改变

见:


由于您只需要
browser.d.ts
进行类型转换,因此此解决方案将有效

您可以添加:

declare var browser: any;

在您使用
浏览器的文件顶部。运行时

否,它会给出边缘扩展的未定义错误。当我用浏览器替换chrome时,同样的脚本也适用于我。我试图用typescript中的browser替换chrome,但在构建时失败了,因为找不到浏览器名称空间。如何添加browser.d.ts类型依赖项。请确保按照此处的说明在Edge中多填充chrome命名空间。上有特定于Firefox的键入功能,上有浏览器polyfill(部分支持Edge)的键入功能。您能详细介绍一下吗?microsoft Edge扩展允许“browser.runtime.getUrl”等功能,当我们想从typescript转换到javascript文件时,typescript编译器会抛出一个错误,如“browser undefined”。。由于我们没有像chrome那样为“browser.d.ts”定义正确的类型,为了绕过上面提到的错误,我们可以添加这一行declare var browser:any;然后一切都会按预期进行