0

I'm new to creating chrome extensions and I just want to get all cookies from the sites that I visit. The issue is that when I load a site nothing happens. I get no errors and no logs for the cookies that I want to get. Can anyone help me understand what I'm doing wrong? Thanks!

manifest.json

{
    "manifest_version": 2,
    "name": "xxxxxxxx",
    "version": "0.8",
    "permissions": [
        "cookies",
        "tabs",
        "http://*/*",
        "https://*/*",
        "<all_urls>"
    ],
    "background": {
        "scripts": ["background.js"]
    }
}

background.js

function cookieInfo(){
    chrome.cookies.getAll({}, function (cookies){
        console.log(cookies)
    });
}

cookieInfo();
Michael
  • 1,454
  • 3
  • 19
  • 45
  • Is the function even running? – Barmar May 28 '20 at 01:19
  • @Barmar I don't think so, honestly not sure where I'm going wrong here. – Michael May 28 '20 at 02:16
  • Then it sounds like your question is actually how to make the background script of a chrome extension run. The cookie stuff is irrelevant. – Barmar May 28 '20 at 02:18
  • @Barmar ok I will update my question. – Michael May 28 '20 at 02:18
  • Maybe it should be a content script rather than a background script. – Barmar May 28 '20 at 02:23
  • @Barmar what's the difference? – Michael May 28 '20 at 02:24
  • 1
    The background script needs to register a listener for an API event, otherwise it rarely makes sense to use a background script. Your current code will run only once when the extension runs on browser startup or after it was re-enabled or re-installed. In other words it doesn't do anything particularly useful. Depending on your preferred method of learning you may want to start with the documentation/tutorial or just inspect the official [demo extensions](https://developer.chrome.com/extensions/samples). – wOxxOm May 28 '20 at 06:50
  • @wOxxOm I was able to find a good resource that helped me solve this issue. Sloreti's solution is correct. – Michael May 28 '20 at 13:05

1 Answers1

2

Background scripts do not log to a specific web page's console. Visit chrome://extensions/ and click on "Inspect views background page" for your extension.

enter image description here

sloreti
  • 491
  • 4
  • 11