Skip to content Skip to sidebar Skip to footer

How To Use Chrome Extension Api With Angular?

I am working on a chrome extension, I have a 'background.js' which it filters the url and fetchs data from my api. When the conditions is meet I am sending a message from 'backgrou

Solution 1:

///<reference types="chrome"/>
import {chrome} from'@types/chrome';
// Remove chrome import

IMPORTANT: Must add three slashes before reference.

If still it doesn't work then add "Chrome" in tsconfig.json types.

compilerOptions: ["types": [ "Chrome" ] ]

Solution 2:

Add the line

///<reference types="chrome"/>

to the very top of your TS file (preferably line 1). (DO NOT OMIT THE 3 SLASHES IN THE BEGINNING)

Also run the command

npm install --save@types/chrome 

Things will start working after that.

Solution 3:

In my case, I installed npm install --save @types/chrome

so file stop showing an error Cannot find name 'chrome' when build

then I'm trying to build the library by using the command ng build but it was broken because it didn't find a chrome so what I did?

I added this line ///<reference types="chrome"/> on top of file public-api.ts

Note: Must add three slashes(///) before reference.

Post a Comment for "How To Use Chrome Extension Api With Angular?"