0

I am trying to update an existing chrome extension that used background page, I found something here and here I get no error but the popup is never displayed. I even tried to go back to some old chrome version to allow me trying the manifest 1 code but the time doesn't increase. I am sorry for all this code but I have no idea where the problem is coming from.

Manifest.json

    {

"manifest_version": 2,
    "background": {
    "scripts": ["background.js"]
  },

   "browser_action": {
      "default_icon": "icon.png",
      "popup": "popup.html"
   },
   "description": "Count the time on Facebook",
   "name": "Compteur Facebook ",
   "permissions": [ "tabs" ],
   "version": "1.0"
}

popup.html

 <!doctype html>
    <html>
      <head>
      <script src="popup.js"></script>
      </head>
      <body>
     The amount of time you have spent on <span>Facebook</span> is: 
    <br /><br />
    <script>document.write(prettyDate(localStorage.getItem('facebookCounter')));</script>
    <br /><br />

    <div>
    Having a problem?<br />

    <button>Reset</button>
    </div>
    </body>
    </html>

popup.js

chrome.extension.getBackgroundPage();

    function resetCounter(){ localStorage.setItem('facebookCounter',0)}

function prettyDate(time){            
        var responce= "About " + Math.round(time) + " seconds"
        return responce
}
function main() {}

document.addEventListener('DOMContentLoaded', function () {
  document.querySelector('button').addEventListener('click', clickHandler);
  resetCounter();
  main();
});

background.js

var a = 0
  var x
  function timedCount()
  {
    a = parseInt(localStorage.getItem('facebookCounter'))

    chrome.tabs.getSelected(null, function(tab) 
    {

        theurl = tab.url.substr(0,24)

        if(theurl == "http://www.facebook.com/")
        {
            a=a+1 
            localStorage.setItem('facebookCounter',a)
        }
    });

    setTimeout("timedCount()",1000);  

  } 

  setTimeout("timedCount()",1000); 

1 Answer 1

1

For the popup to appear, you have to modify your "manifest.json", replacing
"popup": "popup.html"
with
"default_popup": "popup.html"

You can find more info about the transition from Manifest v1 to Manifest v2 here.

Also, note that you probably need to make several changes to make your extension more efficient (e.g. turning your background page into an event page, or capturing some events instead of using a timer fired every second). This transition guide might be a good place to start.

1
  • Also, you'll have to remove the inline script code from popup.html that does the document.write, and implement similar functionality from popup.js
    – rsanchez
    Jun 2, 2013 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.