0

I'm particularly referring to this https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/theme/getCurrent javascript method as i want to see information about the current theme I'm using on the browser. But when I for ex: call the function in console.log I see no output in the devtools console.

I have tried printing normal debugging statements on the console and they work fine. The method says it returns a promise. I'm guessing maybe there's a special way to handle them. I just want to see the contents of theme object so that I can manipulate it.

console.log(browser.theme.getCurrent());
console.log(theme.colors);
function getStyle(themeInfo) 
{
  if (themeInfo.colors) 
  {
    console.log("accent color : " +  themeInfo.colors.accentcolor);
    console.log("toolbar : " + themeInfo.colors.toolbar);
  }
}

async function getCurrentThemeInfo() 
{
  var themeInfo = await browser.theme.getCurrent();
  getStyle(themeInfo);
}

getCurrentThemeInfo();

manifest.json

{

    "manifest_version": 2,
    "name": "test",
    "version": "1.0",

    "description": "tests the theme detecting abilities in Firefox",

    "permissions": ["theme"],


    "content_scripts": [
    {
      "matches": ["*://*.mozilla.org/*"],
      "js": ["check-theme.js"]
    }
  ]
    "applications": {
        "gecko": {
          "id": "theme@example.org"

        }
      }

  }

I have tried these above codes. First one is just naively trying to print the contents of theme and the second one is an example from the MDN page(link above). Both output nothing.

stealth225
  • 165
  • 1
  • 1
  • 11
  • Possibly related / possibly the problem: [Google Chrome / Firefox do not see extension output in console](https://stackoverflow.com/a/38920982) – Makyen Oct 05 '19 at 18:49
  • With respect to your `console.log(browser.theme.getCurrent());`, please see: [How do I return the response from an asynchronous call?](https://stackoverflow.com/q/14220321) – Makyen Oct 05 '19 at 18:51
  • For the `console.log()` commands which you entered in the console: Please provide the response you got from the commands. What response you received will tell us quite a bit. In addition, the info we need is: which console you were using for the `console.log()` commands? Which console were you looking at for the output of your extension? In what context was the code you've provided executing (the best way to tell us is to provide a manifest.json file and tell us which file the code was in)? Basically, there are a number of possible issues. We need more information to narrow down the problem. – Makyen Oct 05 '19 at 18:57
  • @Makyen since I'm writing this for an extension, I tried the console logs on Firefox's devtools console. I have edited my post with the manifest.json file. Note: If I console.log simple "hello" statement it works fine but when I `console.log(browser.theme.getCurrent()); ` do this, I see blank console. – stealth225 Oct 06 '19 at 07:06
  • 1
    Please look at the link which I provided in my first comment. There are a few/several possible consoles which you might be using. Some of them will show you nothing from the background context (e.g. background scripts) and won't be running console commands in the context of your extension. Of the available consoles, you should be using the Add-on Debugger, which should show a URL like `about:devtools-toolbox?type=extension`. Please see that linked answer for how to open the appropriate one for your extension (I just updated it; it was a bit dated). – Makyen Oct 06 '19 at 07:40
  • You are trying to use `browser.theme.getCurrent()` in a content script. It is not available to content scripts. If you want to use it, you need to do so from a script in the background context. In addition, many of the URLs matched by `"*://*.mozilla.org/*"` have [content scripts explicitly blocked](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Content_scripts), so you won't see the errors that attempting to make those calls would normally produce from your content script. – Makyen Oct 06 '19 at 20:59

0 Answers0