Chrome extensions: get javascript to work without opening html page

I know there is a way to get JS to work in the chrome extension: just include the default_popup parameter in your .json manifest to indicate the HTML page, then include JS in the HTML using <script> . But is there a way to get JS to do some things without having to open an HTML page (for example, change the extension icon without an HTML popup)?

+4
source share
1 answer

Yes, this is called a man page . You can create it without a .html file, but it will dynamically create it for you, called _generated_background_page.html .

You can add the following to your manifest.json to specify the background page:

 { "name": "My extension", ... "background": { "scripts": ["background.js"] }, ... } 

To view the background page, go to chrome://chrome/extensions activate "Developer Mode" and you can see the background image using the developer tools:

extensions tab

In your example, by changing the icon, you can use chrome.browserAction .

+7
source

Source: https://habr.com/ru/post/1444950/


All Articles