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();
8
  • Is the function even running? Commented May 28, 2020 at 1:19
  • @Barmar I don't think so, honestly not sure where I'm going wrong here. Commented May 28, 2020 at 2: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. Commented May 28, 2020 at 2:18
  • @Barmar ok I will update my question. Commented May 28, 2020 at 2:18
  • 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. Commented May 28, 2020 at 6:50

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Will the logs show in there?
Yup, that is correct

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.