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

Talk about add-ons and extension development.
Post Reply
User avatar
RejZoR
Posts: 130
Joined: April 18th, 2004, 3:21 am
Location: Europe/Slovenia
Contact:

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

Post by RejZoR »

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: 6403
Joined: February 3rd, 2009, 6:29 pm

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

Post by morat »

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
User avatar
RejZoR
Posts: 130
Joined: April 18th, 2004, 3:21 am
Location: Europe/Slovenia
Contact:

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

Post by RejZoR »

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: 6403
Joined: February 3rd, 2009, 6:29 pm

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

Post by morat »

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
User avatar
RejZoR
Posts: 130
Joined: April 18th, 2004, 3:21 am
Location: Europe/Slovenia
Contact:

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

Post by RejZoR »

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: 6403
Joined: February 3rd, 2009, 6:29 pm

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

Post by morat »

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
Post Reply