react-chrome-extension-boilerplate icon indicating copy to clipboard operation
react-chrome-extension-boilerplate copied to clipboard

Handle inject page on extension icon click

Open teckays opened this issue 8 years ago • 6 comments

Is there a way to trigger Dock opening on extension icon click event?

teckays avatar Dec 16 '16 15:12 teckays

You can listen browser action and execute script in the tab via background page. (inject script in background page)

jhen0409 avatar Jan 01 '17 08:01 jhen0409

@jhen0409 I am trying to do this also. Can you please provide an example?

I tried this, but it is not working:

    chrome.browserAction.onClicked.addListener((tab) => {
        chrome.tabs.executeScript(tab.id, { code: fetchRes, runAt: 'document_end' }, cb);
    });

yiziz avatar Oct 07 '17 05:10 yiziz

@teckays @yiziz Did either of you ever get this to work properly? Same problem here and can't figure it out.

With your implementation @yiziz I do indeed see the load inject bundle success! message in the console upon clicking the extension icon, but the dock does not appear nor does it seem to actually affect the page at all.

cosst avatar Mar 15 '18 16:03 cosst

@jhen0409 Perhaps you'd be willing to elaborate? What @yiziz posted doesn't seem to work. Thanks!

cosst avatar Mar 19 '18 16:03 cosst

@jhen0409 did you manage to resolve this? I tried it and I'm getting an error of chrome.runtime.lastError of {message: "Could not establish connection. Receiving end does not exist."}

ianoti avatar Sep 20 '18 17:09 ianoti

I use this method content.js

background.js

chrome.browserAction.onClicked.addListener(function (tab) {
  // Send a message to the active tab
  chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
    var activeTab = tabs[0];
    chrome.tabs.sendMessage(activeTab.id, {
      message: 'clicked_browser_action',
    });
  });
});
chrome.runtime.onMessage.addListener(function (request) {
  if (request.message === 'clicked_browser_action') {
    // check if already injected, otherwise
	document.createElement()
	reactDOM.render()
  }
});

palashkaria avatar Jun 11 '20 15:06 palashkaria