0

I want to create an extension that does the following:

  1. have a pageaction or browseraction (not sure which one is more appropriate).
  2. if the url of the page is found in my database/service then allow the Action to have/show a popup where some information from my service is displayed.
  3. Otherwise make the Action button look disabled and show no popups

I have been trying a background script with a popup. Have not been able to show contents in the popup set to the results from my service. For the communication between the background and the popup I used the advice here: How to communicate between popup.js and background.js in chrome extension? but did not manage to get it worked. and debugging the popup has been almost impossible.

I tried creating an iFrame using content_script in the main page. That did not go well at all. Lots of cross frame exceptions.

Jeff Saremi
  • 2,674
  • 3
  • 33
  • 57
  • In chrome you can use declarativeContent API in event page to register the URLs for your page action, [example](https://developer.chrome.com/extensions/samples#search:declarativecontent). – wOxxOm May 30 '18 at 06:40
  • @wOxxOm I don't think what I want to do on the URL is achievable using declarativeContent. A service call must be made to determine if the URL qualifies or not. – Jeff Saremi May 30 '18 at 14:20

1 Answers1

0

I think for what you're doing you should look at page actions. Page actions are greyed out by default but you can choose to show them. Having a look at How do I make page_action appear for specific pages? you could update it by looping through your list of URLs

function checkForValidUrl(tabId, changeInfo, tab) {
    chrome.storage.local.get(['urls'], function(result) {
        for (var item in result.urls) {
            if (tab.url.indexOf(item) > -1) {
                chrome.pageAction.show(tabId);
                //set url to the URL you want for the popup
                chrome.pageAction.setPopup({tabId: tabId, popup: url})
                //or you could create a new window - see https://developer.chrome.com/extensions/windows.html#method-create
            }
        }
    });
}

chrome.tabs.onUpdated.addListener(checkForValidUrl);

Edit: Sorry, I realise now that you're actually trying to debug the popup instead. Hopefully this helps for checking the URL though

MagnetPlant
  • 196
  • 1
  • 7