-1

I have an issue with onclick browser action. All the time it shows TypeError: browser is not defined if i do put in try catch Tried manually inseritng into firefox console, no success still not defined. Using firefox 55. How to overcome the issue?

console.log("Start 1")
function run(){console.log(1)}
browser.browserAction.onClicked.addListener(run);

var interval1Id = setInterval(function(){

 var id = document.querySelector(".myclass").id

 document.getElementById('m1).contentWindow.document.getElementById(id).click();
 var newDate = new Date();
   console.log("Function executes at : " +newDate ) 
},10000); 

Manifest

    {
"applications": {
  "gecko": {
    "id": "at@ex.com",
    "strict_min_version": "52.0"
  }
},
"browser_action": {
    "default_icon": {
      "18": "icons/btn18.png",
      "38": "icons/btn18.png"
    },
    "default_title": "Whereami1?"
  },
  "manifest_version": 2,
  "name": "FF 1a",
  "version": "1a",
  "description": "Refresh",
    "background": {
    "scripts": ["b.js"]
  },
  "content_scripts": [
    {
    "matches" : ["https://*/*"],
    "js": ["scr.js"]
    }
  ],
  "permissions": ["webNavigation","tabs","notifications","activeTab"],
  "web_accessible_resources": ["icons/btn18.png"]

}
Vladyslav Didenko
  • 1,352
  • 1
  • 14
  • 19
  • What are you trying to achieve? There is no global variable named browser. – Daniel Oct 05 '17 at 14:28
  • The `browser` object is more than likely not available to Content Scripts, and only usable in background scripts – Patrick Evans Oct 05 '17 at 14:37
  • If you would check Firefox web ext developers guide, in their examples they use this variable. Like here: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Your_second_WebExtension I am trying to run function by clicking on an icon of my Web Extension in FF Toolbar – Vladyslav Didenko Oct 05 '17 at 14:38
  • Ive tried to use it in background instead of content script, but nothing happends. Background section in manifest wasnt trigerring any action at all. First line was console log there, which should have succesfully executed that atleast – Vladyslav Didenko Oct 05 '17 at 14:39
  • Are you sure you are looking in the right console? Firefox like Chrome probably uses a separate Dev Tools window for extensions – Patrick Evans Oct 05 '17 at 14:40
  • Duplicate of https://stackoverflow.com/questions/46081284/firefox-webextention-api-typeerror-browser-browseraction-is-undefined – Smile4ever Oct 05 '17 at 14:49
  • Ive tried that, no help:( Wish it could be that easy – Vladyslav Didenko Oct 06 '17 at 12:42
  • Please [edit] the question to be on-topic: include a [mcve] that *duplicates the problem*. For Chrome extensions or Firefox WebExtensions you almost always need to include your *manifest.json* and some of the background, content, and/or popup scripts/HTML, and often webpage HTML/scripts. Questions seeking debugging help ("why isn't my code working the way I want?") must include: (1) the desired behavior, (2) a specific problem or error and (3) the shortest code necessary to reproduce it *in the question itself*. Please also see: [What topics can I ask about here?](/help/on-topic), and [ask]. – Makyen Oct 07 '17 at 05:28
  • Your code mixes things which must be done in the background with things which must be done in a content script. Thus, it's not possible to determine what you are actually trying to do in what file, in part because you haven't told us which JavaScript file you've (partially?) included in your question. Also, include the *actual* error which you are seeing. – Makyen Oct 07 '17 at 05:30
  • I suggest you read the [Anatomy of a WebExtension](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Anatomy_of_a_WebExtension) page (perhaps work through reading the pages linked from there). It has overall architecture information which should help your understanding of how things are generally organized/done. – Makyen Oct 07 '17 at 05:30
  • There are [various appropriate consoles for your extension](https://stackoverflow.com/a/38920982/3773011). You should become familiar with them, as they are where you will see error information and any console output you choose to produce. – Makyen Oct 07 '17 at 05:37
  • I've finally figured that out. Thanks for a tip, otherwise i would be lost. Issue was definitely related to different consoles , which I was monitoring for an output. Regular dev console doesnt display everything – Vladyslav Didenko Oct 27 '17 at 22:28

1 Answers1

0

Output of background script goes to specific Debug page, not to output of firefox console . Extensions-> Debug Extension -> Allow debugging-> Debug on extensions. New console outputs, where everything comes to display Browser variable only supported in Debug console, not in developer tools console

Vladyslav Didenko
  • 1,352
  • 1
  • 14
  • 19
  • While this is moderately accurate, if it's a quotation, then you need to state the source. Further, there is no way to determine that this is the actual answer based on your question. In fact, based on your question, it *can't* be the only thing that is needed or your question. It does cover part of what's implied by your question. It generally only covers the issue that you want access to a console which is in the context of the extension, as opposed to the page context. – Makyen Oct 07 '17 at 05:37