Hi all,
I’m making my first extension, and mostly it’s been pretty smooth, but I’ve ran into the first problem that I can’t work out. I’ve tried doing it so many different ways, and nothing works. Here’s the issue…
I have an IF statement in my content script which checks if a XMLHttpRequest has been successful. The result is sent to the console log. That all works fine. However the IF statement is meant to also change the browserAction icon to tell the user the result of the XMLHttpRequest, but the icon nether changes.
Here’s the code:
function reqListener () {
console.log(this.responseText);
}
var oReq = new XMLHttpRequest();
oReq.addEventListener("load", reqListener);
oReq.open("GET", 'https://web.archive.org/save/' + encodeURI(decodeURI(location.href)));
oReq.onload = function () {
console.log('DONE: ', oReq.status);
if (oReq.status==200) {
console.log('Working') ;
browser.browserAction.setIcon({
path: "icons/aws-32-worked.png"
});
}
else {
console.log('Not working') ;
browser.browserAction.setIcon({
path: "icons/aws-32-failed.png"
});
}
};
oReq.send();
Any ideas what I’m doing wrong? I’d also be fine doing it with
browserAction.setBadgeText(), but I can’t get that to work either.
Let me know if you need anymore information. Here’s my manifest:
{
"manifest_version": 2,
"name": "AutoWaybackSaver",
"version": "1.0",
"permissions": [
"https://web.archive.org/save/*",
"storage",
"tabs"
],
"description": "Saves every page you visit to archive.org's Wayback Machine",
"icons": {
"48": "icons/aws-48.png",
"96": "icons/aws-96.png"
},
"browser_action": {
"default_icon": "icons/aws-32.png",
"default_title": "AutoWaybackSaver"
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["awm.js"]
}
],
"options_ui": {
"page": "options.html"
},
"applications": {
"gecko": {
"id": "AutoWaybackSaver@example.com"
}
},
"background": {
"scripts": ["background.js"]
}
}