Launch / call Chrome extension from web page

For the project I'm currently working on, I need to know if the Chrome extension can be called.

Ie, clicking on the button (or link) on my page will cause the โ€œRead Itโ€ extension, something like this.

+10
source share
3 answers

You can enter content-scripton each page (register it in the manifest extension ) and change the html page to add your own buttonor awith your custom identifier.

The runtime example explains this pretty well how you fire the event from the page to your content script. After you control the trigger, you can do whatever you want as extension logic.

Also keep in mind that for each page the user visits, you will need to add an extension content-script. It is impossible to actually start your execution content-scriptfrom the page if this is what you requested.

+3
source

Yes it is possible. You can write the so-called Content Script to change the page and bind event handlers to links or buttons.

+1
source

background.js content.js.

chrome.tabs.sendMessage(tabId, {}, function() { ... });

in the background to send messages to the content script that is entered on each web page that opens when the extension is installed and enabled. On content.js script use

chrome.runtime.onMessage.addListener(function(req, sender, callback) {  
    < here use condition to find out when this exetnsion popup.html should be opened and call the callback function which was passed in the argument list intially >
    callback("something");
});

Here the callback function is defined in background.js and passed to content.js - this is the code to open a new extension window, such as

var panel_props = {
            type: 'panel',
            'width': width,
            'height': height,
            'left': left,
            'top': top,
            url: "chrome-extension://" + <extensionid>+ "/index.html"   
          }

          chrome.windows.create(panel_props ,function (newWindow) { 
              vid = newWindow.id;
          });
0
source