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 "background.js". And I want to catch it from Angular component.


... chrome.pageAction.show(tab.id, () => { chrome.runtime.sendMessage({data: dataFromAPI}) }); ...

I ran npm install --save @types/chrome.


import {Component} from '@angular/core'; import {chrome} from '@types/chrome'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { constructor() { chrome.runtime.onMessage.addListener( data => console.log(data)); } }

But WebStorm says, ".../node_modules/@types/chrome/index.d.ts' is not a module. "

How can I use Chrome Api from Angular Component?

/// <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" ] ]

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.



  • How to use Chrome Extension Api with Angular?
  • Ruby: Prawn PDF out of memory when using the group method
  • creating accompanying slides for bookdown project
  • Create new data frame with multiple subsets of same variable
  • Fatal error: Cannot declare class
  • How to restrict the upload image ratio to 16:9 in codeigniter?
  • Oracle APEX | Validate Tabular form Row by Row
  • Matlab structure in Python [duplicate]
  • How can I run my ionic app on a physical device (Wiko phone) on Windows?
  • gitlab throwing - failed to store ssl session
  • making an array of bigInteger of size biginteger in java
  • Firebase Database OutofMemory Error
  • How to add an Auth Token in every request using AFIncrementalStore?
  • How to delete yarn logs
  • Starting a javascript prompt after a button is clicked
  • jquery: Disable/Enable button not working after reset
  • Python: Why am I getting a UnicodeDecodeError?
  • get value using jquery
  • NextJS auth with an external server
  • How to use grep to output unique lines of code from a file?
  • C++ Time measurement of functions
  • Unknown type name with typedef struct in C
  • android 3G signal strength
  • Adding custom message on Thank You page by shipping method
  • Can I switch the 'connected' user within an sql script that is sourced by mysql?
  • Gitlab: copy project to other git lab repository
  • async GET request with body from browser
  • Unable to connect to Azure MySQL Database through Azure Function - C#
  • How to get the Owner of the ContextMenu (from Silverlight 4 toolkit)?
  • Authorize Attribute Authentication with Postman in Web Api
  • flex tree gets chopped even after using scroll bar
  • Copy and paste data from multiple workbooks to a worksheet in another Workbook
  • Multiplying polynomials/simplifying like terms
  • using maven pom while creating jar:test-jar some times it says JAR will be empty - no content was ma
  • LinkedIn API: Access Denied when getting Access Token
  • How to use Streams api peek() function and make it work?
  • PHP Permalinks.. how to change?
  • media foundation H264 decoder not working properly
  • Running R's aov() mixed effects model from Python using rpy2
  • Access to a Matlab gui from the web