EpokK
EpokK

Reputation: 38092

"addon" is undefined in panel ( firefox-addon )

I meet a strange thing with Firefox addon development. Why addon is undefined ?

-- main.js --

var login = panels.Panel({
  contentURL: data.url("login.html"),
  contentScriptFile: data.url("login.js")
});

login.port.on('send', function onSend(login, password) {
  core.getTokens(login, password);
  login.hide();
});

-- login.js --

document.querySelector('#ok').addEventListener('click', function(event) {
    addon.port.emit('send', document.querySelector('#login').value, document.querySelector('#password').value);
});
document.querySelector('#cancel').addEventListener('click', function(event) {
    addon.port.emit('close');
});

I got this error: login.js: addon is not defined. So, what's wrong? Thanks.

Documentation

Upvotes: 1

Views: 186

Answers (1)

paa
paa

Reputation: 5054

The addon object is defined when your script is included through a script tag by the login.html file.

Since you use the contentScriptFile option, you have to use the self object.

Upvotes: 2

Related Questions