Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using chrome extension apis in typescript

I'm building a chrome extension written in TypeScript. I'm using WebStorm and I added the chrome-DefiniteltyTyped library in my project.

However, when I write this in my typescript code : chrome.extension.getURL I got an error : cannot find name 'chrome'.

Because of this, my javascript file is not generated and I cannot use it in my extension.

Do you guys have any solution?

like image 557
Tristan Djahel Avatar asked Mar 04 '15 00:03

Tristan Djahel


People also ask

Can Chrome extensions use React?

Quickly start up a Chrome extension with Create React AppCreate React App doesn't work with Chrome extensions straight out of the box. The reason for that is React uses in-line scripts, which violates Chrome security guidelines.


1 Answers

As of typescript 2 (or 2.x, not sure), you should import the chrome types from @types.

in package.json:

"devDependencies": {     ...     "@types/chrome": "0.0.35", // or just npm install --save-dev @types/chrome 

And in tsconfig:

    "types": [         //(various types, e.g. jquery, core-js),         "chrome"     ] 
like image 116
dfl Avatar answered Sep 18 '22 16:09

dfl