How to make a toolbar in Google Chrome?

后端 未结 3 1959
不思量自难忘°
不思量自难忘° 2020-12-01 01:18

I\'m exploring Google Chrome extensions for the first time. I would like to create what appears as a toolbar along the top of the page when you click the extension icon, muc

3条回答
  •  孤街浪徒
    2020-12-01 02:23

    Although this answer shows two ways to create a toolbar in Chrome, I strongly recommend using page action or browser action badges. These do not take as much space as toolbars, and can also be used to show a panel on click, and even get temporary host permissions to interact with the page.

    And for those who do not really need a toolbar, but a sidebar, there is an active proposal for a chrome.sidebar API. This is just a proposal, whether and when it will be implemented is not set in stone yet.

    The chrome.infobars API

    This section used to show a demo using the chrome.infobars API. This API has never been to the stable channel, and will be removed; do not use it.

    Content scripts

    Creation of toolbars using content scripts is tricky. You have to insert code in the page, and even modify the structure of the document, which could break some pages on the internet.

    To create a toolbar using content scripts, the following steps have to be taken:

    1. Execute a content script on the page which runs the next two steps.
    2. Insert the toolbar (