Search code examples
javascriptgoogle-chromegoogle-chrome-extensiontypescriptwebstorm

Using Google 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 wrote 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.

Is there a solution?


Solution

  • That should work fine : https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/chrome/index.d.ts

    TIP: make sure you have a reference tag added:

    /// <reference path="pathTo/chrome.d.ts"/>