0
votes

I'm new to Firefox addon development and am having some trouble finding a solution to my problem in the MDN documentation. My addon is very simple right now, I have a main.js file that opens a new chrome page

var buttons = require('sdk/ui/button/action');
var tabs = require("sdk/tabs");

var button = buttons.ActionButton({
  id: "mozilla-link",
  label: "Visit Mozilla",
  icon: {
    "16": "./icon-16.png",
    "32": "./icon-32.png",
    "64": "./icon-64.png"
  },
  onClick: handleClick
});
var addontab = require("sdk/addon-page");
var data = require("sdk/self").data;

function handleClick(state) {
require("sdk/tabs").open(data.url("chrome://test_addon/content/data/index.html"));
}

Inside that chome page I want to access a list of open tabs; however, this is where I run into a problem. Adding necessary JS, such as the code below results in an error:

var tabs = require('sdk/tabs');
for (let tab of tabs)
console.log(tab.title);

Here is the error, I am obviously calling the script improperly, but I don't know how I'm supposed to be implementing this.

JavaScript error: chrome://test_addon/content/data/index.html, line 12: require is not defined
1

1 Answers

0
votes

The code that runs in the context of chrome://test_addon/content/data/index.html is not sandboxed, so it can't access the SDK APIs.