MozillaZine

Can't figure out what I'm doing wrong (basic extension)

Talk about add-ons and extension development.
RejZoR

User avatar
 
Posts: 130
Joined: April 18th, 2004, 3:21 am
Location: Europe/Slovenia

Post Posted May 3rd, 2018, 1:57 am

Can someone help me coz I can't figure out the damn thing. I made the same extension for Opera in like 10 minute with ZERO pre-existing coding knowledge using just their basic tutorials, but I can't seem to do the same for Firefox. I've made all the code so there aren't any errors anymore, I can temporarily import it into Firefox, icon appears in the toolbar, but upon clicking it, nothing happens. It should always open a new tab and load specified webpage in it. In Opera I also had to specify a tab permission, but for Firefox, I have no clue what to do. Read the dev page and it's next to useless.

What am I doing wrong here?

manifest.json:

Code: Select all
{

  "description": "Adds ProtonMail icon to toolbar.",
  "manifest_version": 2,
  "name": "ProtonMail ",
  "version": "1.0",
  "homepage_url": "http://www.rejzor.tk",
  "icons": {
    "64": "icons/ProtonMail_64.png",
    "48": "icons/ProtonMail_48.png",
    "32": "icons/ProtonMail_32.png",
    "16": "icons/ProtonMail_16.png"
  },

  "background": {
    "scripts": ["ProtonMail.js"]
  },

  "browser_action": {
    "default_icon": "icons/ProtonMail_32.png"
  }

}


ProtonMail.js:

Code: Select all
function openMyPage() {
  console.log("injecting");
   browser.tabs.create({
     "url": "https://mail.protonmail.com"
   });
}
My webpage and blog: http://www.rejzor.tk

morat
 
Posts: 2716
Joined: February 3rd, 2009, 6:29 pm

Post Posted May 3rd, 2018, 7:54 am

Where is the browserAction click listener to listen for a click on the icon?

browserAction
http://developer.mozilla.org/en-US/Add- ... wserAction

Sample extensions - filter by browserAction
http://developer.chrome.com/extensions/ ... wseraction

RejZoR

User avatar
 
Posts: 130
Joined: April 18th, 2004, 3:21 am
Location: Europe/Slovenia

Post Posted May 3rd, 2018, 8:35 am

I thought .js file has the necessary commands for it. At least that was the case when I was making extension for Opera and it was dead easy. Here it seems so damn fiddly even though the principle appears to be the same. Can you drop me the code how I'm suppose to do it? I don't get it how I'm suppose to change the browserAction to make it do what I want it to do...
My webpage and blog: http://www.rejzor.tk

morat
 
Posts: 2716
Joined: February 3rd, 2009, 6:29 pm

Post Posted May 3rd, 2018, 11:09 am

Try this:

* ProtonMail.js

Code: Select all
browser.browserAction.onClicked.addListener(function (tab) {
  browser.tabs.create({
    url: "https://mail.protonmail.com/",
  });
});

browser.browserAction.onClicked
https://developer.mozilla.org/en-US/Add ... /onClicked

browser.tabs.create
http://developer.mozilla.org/en-US/Add- ... abs/create

RejZoR

User avatar
 
Posts: 130
Joined: April 18th, 2004, 3:21 am
Location: Europe/Slovenia

Post Posted May 10th, 2018, 10:07 am

Now it just keeps on saying the extension is corrupt no matter how I try to install it. This is idiotic.
My webpage and blog: http://www.rejzor.tk

morat
 
Posts: 2716
Joined: February 3rd, 2009, 6:29 pm

Post Posted May 12th, 2018, 9:42 am

I successfully loaded the following temporary extension in the about:debugging page with no problems.

* manifest.json

Code: Select all
{

  "manifest_version": 2,

  "name": "Tweaks",
  "description": "Personalize Mozilla Firefox.",
  "version": "1.0",
  "homepage_url": "http://www.mozillazine.org/",

  "icons": {
    "48": "icons/icon48.png"
  },

  "background": {
    "scripts": ["background.js"]
  },

  "browser_action": {
    "default_icon": "icons/icon16.png"
  }

}

* background.js

Code: Select all
browser.browserAction.onClicked.addListener(function (tab) {
  console.log(tab);
  browser.tabs.create({
    url: "http://www.mozillazine.org/",
  });
});

Firefox 60.0
Windows 7 SP1 32-bit

Unable to install my own extension - Corrupted error message
http://discourse.mozilla.org/t/13258/8

You can also ask for help in the following forum.

Mozilla Discource Addons Development forum
http://discourse.mozilla.org/c/add-ons/development

Return to Extension Development


Who is online

Users browsing this forum: No registered users and 1 guest