How to get my icon to display in my Firefox Addon? - firefox-addon

I have created an Addon and uploaded it to addons.mozilla.org and it works ok, but it's displaying a default icon instead of my icon. I don't get this problem with Chrome.
My manifest.json file looks like:
{
"manifest_version": 2,
"name": "Handcash handle converter",
"version": "1.4",
"description": "Get a receiving address for a Handcash $handle",
"icons": {
"48": "handcash48.png",
"64": "handcash64.png",
"128": "handcash128.png"
},
"browser_action": {
"default_title": "Handcash handle converter",
"default_popup": "./popup/popup.html"
},
"homepage_url": "https://www.handcash.io",
"short_name": "HandcashConv",
"content_security_policy": "script-src 'self' https://api.moneybutton.com ; object-src 'self'",
"permissions": [
"storage",
"clipboardWrite"
]
}
I tried putting the icons in their own directory and at the root of the extension but no joy. The extension looks like this in Firefox:
Full source code in case you're interested: https://github.com/markallisongit/handcash-chrome

The icons entry of the manifest.json refers to icons used in the addon listing, addon management page, etc. What you want here is to set the icon of the browserAction button in the toolbar. If you have a look at the browser_action page on the MDN, you'll notice a default_icon setting, and I believe this is what you're looking for :
Use this to specify one or more icons for the browser action. The icon
is shown in the browser toolbar by default.
Icons are specified as URLs relative to the manifest.json file itself.
You can specify a single icon file by supplying a string here:
"default_icon": "path/to/geo.svg"
To specify multiple icons in different sizes, specify an object here.
The name of each property is the icon's height in pixels, and must be
convertible to an integer. The value is the URL. For example:
"default_icon": {
"16": "path/to/geo-16.png",
"32": "path/to/geo-32.png"
}
In the end, you should update your manifest.json so that it includes this default_icon setting, something like this:
{
"manifest_version": 2,
"name": "Handcash handle converter",
...
"browser_action": {
"default_title": "Handcash handle converter",
"default_popup": "./popup/popup.html",
"default_icon": {
"48": "handcash48.png",
"64": "handcash64.png",
"128": "handcash128.png"
}
},
...
}

Related

Allow sharing a file in iOS on standalone mode in a WebApp

I have a WebApp and it works alright in both Android and iOS environments. The problem is, in one of the screens, the WebApp generates (and displays) a PDF file, which should be shareable through Email, WhatsApp, Telegram, etc.
Android does allow the share option in the standalone display mode, but iOS just doesn't. I need to know if there's any way I can actually exit the WebApp mode into plain good-old-browser mode when opening the pdf file, so that the user can actually share it with his/her contacts through the browser's native share dialog.
These are the contents of the manifest.json file
{
"name": "Test App",
"short_name": "TestApp",
"icons": [
{
"src": "/icon-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/icon-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
],
"start_url": "https://example.com?a2hs=1",
"scope": "/",
"display": "standalone",
"orientation": "portrait",
"background_color": "#000000",
"theme_color": "#000000"
}
So far, I've tried:
using Display PDF in the pdf link.
using javascript to force-open a new window:
test
<script>
$(function(){
$('#pdf').click(function(e){
e.preventDefault();
window.open($(this).attr('href'), '_blank');
return false;
});
});
</script>
None of those solutions worked out.
Also, I tried changing the display: property in the manifest.json file to minimal-ui - that does allow to share the file/url but that removes the WebApp look & feel, so it's not an option.
Any ideas? Thanks!
I managed to find a solution. I created this alias subdomain:
pdf.example.com
Then, I linked the pdf to the alias subdomain:
Display PDF
iOS recognizes this as another server, so it automatically forces the load of the file in a new tab in Safari, exiting the current standalone mode of the webapp.

Firefox webextension: Save page as html or text

With the new firefox webextensions: Is there a way to save the current page (or a part of it) as html (or text) to disk? If not, how are the chances, such an API will be implemented in the future?
I didn't find any suitable API and appreciate any help.
Regards
There are probably several ways to do this. The following will get you started. It saves the webpage in the currently focused tab in the active window to the browser's default downloads path. The file name is set to 'samplePage.html' (you can change that by modifying the filename value in the downloads.download() options; or you can remove that field entirely and leave it to the default naming).
You will need to store icon images in your webextension package for the user to be able to click on. Also, be sure to navigate to a webpage you want to save before you try to use the webextension; webextensions are not active on the Firefox about:debugging page.
manifest:
{
"name": "SavePage",
"version": "1.0",
"description": "Clicking browser icon saves page html",
"manifest_version": 2,
"icons": {
"48": "icons/clickme-48.png"
},
"permissions": [
"tabs",
"activeTab",
"downloads"
],
"browser_action": {
"default_icon": "icons/clickme-32.png"
},
"background": {
"scripts": ["background.js"]
}
}
background script:
/* BACKGROUND SCRIPT
Clicking on browser toolbar button saves the webpage in the
current tab to the browser's default downloads path with a
filename of "samplePage.html". The "tabs" and "downloads"
permissions are required.
*/
browser.browserAction.onClicked.addListener((tab) => {
var currentUrl = tab.url;
function onStartedDownload(id) {
console.log(`Started to download: ${id}`);
}
function onFailed(error) {
console.log(`Something stinks: ${error}`);
}
var startDownload = browser.downloads.download({
url : currentUrl,
filename: 'samplePage.html'
});
startDownload.then(onStartedDownload, onFailed);
});
An alternative approach might be to try to save the webpage to local storage rather than to disk. I have not explored that option.
These pages may be helpful:
downloads.download()
browserAction.onClicked
There may be security risks in giving a webextension these permissions. You will have to weigh the risks for your own usage pattern.

How to see or debug chrome content script in firefox nightly (webextensions)

Trying to port a working chrome extension to Firefox Nightly 46.0a1 and have a simple question! How do I get the content script to execute or see it at all?
Everything else but the content script seam to be running OK as the background script execute and the popup box is visible. I am able to debug these part of the code.
But the content script do not seam to run in any way!
As far as I understand it is supposed to be part of the normal page javascript environment and visible in the debugger - but it is not. Unable to see any error messages anywhere etc.
Might have used some unsupported API by mistake, but still strange that I get no warnings and are unable to see anything.
Any proposal about how to proceed?
Manifest file below:
{
"name": "Bla Bla",
"version": "0.0.1",
"manifest_version": 2,
"description": "A description",
"homepage_url": "https://aaa.org",
"icons":
{
"16": "icons/lock_red16.png",
"48": "icons/lock_red48.png",
"128": "icons/lock_red128.png"
},
"default_locale": "en",
"background":
{
"scripts":
[
"js/lib/jserror/jserror.js",
"js/lib/lang/languagedb.js",
"js/lib/lz77.js",
"js/lib/pcrypt.js",
"js/lib/pcryptapi.js",
"js/lib/forge.bundle.js",
"js/lib/elliptic.js",
"js/lib/srp6a/biginteger.js",
"js/lib/srp6a/isaac.js",
"js/lib/srp6a/random.js",
"js/lib/srp6a/sha256.js",
"js/lib/srp6a/thinbus-srp6client.js",
"js/lib/srp6a/thinbus-srp-config.js",
"js/lib/srp6a/thinbus-srp6a-config-sha256.js",
"js/pcrypt_shared.js",
"js/pcrypt_extension.js",
"src/bg/background.js"
],
"persistent": true
},
"browser_action":
{
"default_icon":
{
"16": "icons/lock_red16.png",
"48": "icons/lock_red48.png",
"128": "icons/lock_red128.png"
},
"default_title": "Password Crypt",
"default_popup": "src/browser_action/popup.html"
},
"permissions":
[
"clipboardWrite",
"storage"
],
"content_scripts":
[
{
"matches":
[
"http://*/*",
"https://*/*"
],
"js":
[
"js/pcrypt_extension.js",
"src/inject/inject.js"
]
}
],
"externally_connectable":
{
"matches":
[
"https://*.aaa.dk/*",
"https://*.aaa.org/*"
]
},
"web_accessible_resources":
[
"icons/*.png"
],
"applications":
{
"gecko":
{
"id": "benny#aaa.dk",
"strict_min_version": "40.0.0",
"strict_max_version": "50.*",
"update_url": "https://aaa.org/addon"
}
}
}
As far as I understand it is supposed to be part of the normal page javascript environment and visible in the debugger - but it is not.
No, they're not. They run in slightly more privileged contexts separate from the page environment so they can access the webextension APIs.
If you have e10s off you can use the browser toolbox. If it is on you need to use the browser content toolbox instead. You can also try about:debugging, although i'm not sure whether that already works for webextensions.
MDN docs have everything you need to know about debugging WebExt, including content scripts.

Firefox addon shows name but no icon in Customize window

I have recently developed a Firefox addon using the SDK.
However, once installed the icon does not show, but only the name of the addon in the Customize window for the addon bar (or the menu in Australis).
I haven't seen this behavior in other addons, so I'm guessing it is probably something I did wrong.
Maybe I didn't include the right sized icon? My package.json contains the lines:
...
"icon": "data/icons/icon32.png",
"icon64": "data/icons/icon64.png",
...
The icons display well in the widget and in the addon page.
Shouldn't that be enough?
Your code snippet looks correct but it's hard to tell without more context. Here is the full package.json file for an add-on I wrote that works fine for me on Firefox 29+:
{
"name": "transmission-web-helper",
"license": "MPL 2.0",
"author": "Jeff Griffiths",
"version": "0.4",
"fullName": "transmission-web-helper",
"id": "transmission-web-helper#canuckistani.ca",
"description": "a basic add-on",
"icon": "data/icon48.png",
"icon64": "data/icon64.png",
"preferences": [{
"name": "transmissionUrl",
"title": "URL for Transmission RPC",
"type": "string",
"value": "http://localhost:9091/transmission/rpc"
},
{
"description": "If selected, torrents will start automatically.",
"type": "bool",
"name": "transmissionAutostart",
"value": true,
"title": "Auto-start?"
},
{
"description": "If selected, this add-on will print debug .",
"type": "bool",
"name": "transmissionDebug",
"value": false,
"title": "Debug"
}
]
}
Full source for the add-on is on github

Chrome Ext and JQuery Resources must be listed in the web_accessible_resources manifest key in order to be loaded by pages outside the extension

I have Chrome extension that loads jquery-1.8.3.min.js and jquery-ui.js and jquery-ui-base64.css into the content script .
i use them in the content script NOT background script .
i set the configuration ( i think ) right but when i see in the console i getting errors
i can see the icons in the windows just fine , but i still getting the errors in the Chrome window.
is it a bug in chrome im using version 23.0.1271.95 m?
this is the manifist :
{
"name":"Sample communication from content to background",
"description":"This is a sample for Simulating communication from content to background",
"manifest_version":2,
"version":"2",
"background":{
"scripts":["background.js"]
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["jquery-1.8.3.min.js","jquery-ui.js","client.js"],
"run_at":"document_end",
"all_frames": true,
"css":["jquery-ui-base64.css"]
}
],
"web_accessible_resources": [
"client.js","jquery-1.8.3.min.js","jquery-ui.js","jquery-ui-base64.css",
"images/ui-bg_flat_0_aaaaaa_40x100.png",
"images/ui-bg_flat_75_ffffff_40x100.png",
"images/ui-bg_glass_55_fbf9ee_1x400.png",
"images/ui-bg_glass_65_ffffff_1x400.png",
"images/ui-bg_glass_75_dadada_1x400.png",
"images/ui-bg_glass_75_e6e6e6_1x400.png",
"images/ui-bg_glass_95_fef1ec_1x400.png",
"images/ui-bg_highlight-soft_75_cccccc_1x100.png",
"images/ui-icons_222222_256x240.png",
"images/ui-icons_2e83ff_256x240.png",
"images/ui-icons_454545_256x240.png",
"images/ui-icons_888888_256x240.png",
"images/ui-icons_cd0a0a_256x240.png"
],
"permissions": [
"unlimitedStorage",
"http://*/",
"<all_urls>",
"tabs"
]
}
in the jquery-ui-base64.css i changed all the imags url load to something like this :
url(chrome-extension://__MSG_##extension_id__/chrome-extension://__MSG_##extension_id__/images/ui-bg_flat_75_ffffff_40x100.png)
url(chrome-extension://__MSG_##extension_id__/chrome-extension://__MSG_##extension_id__/images/ui-bg_highlight-soft_75_cccccc_1x100.png)
but still im getting the errors:
Denying load of chrome-extension://mmoccjinakdjcmhjdjghhjnihbfkkgkp/chrome-extension://mmoccjinakdjcmhjdjghhjnihbfkkgkp/images/ui-bg_flat_75_ffffff_40x100.png. Resources must be listed in the web_accessible_resources manifest key in order to be loaded by pages outside the extension.
Denying load of chrome-extension://mmoccjinakdjcmhjdjghhjnihbfkkgkp/chrome-extension://mmoccjinakdjcmhjdjghhjnihbfkkgkp/images/ui-bg_highlight-soft_75_cccccc_1x100.png. Resources must be listed in the web_accessible_resources manifest key in order to be loaded by pages outside the extension.
the images are there in the images dir and i can see the icons in the JQuery dialog i created.
EDIT 1)
The following code works for all background\extension related DOM and css
manifest.json
Simple json structure with all permissions defined
{
"name": "My extension",
"version": "1.0",
"permissions": [
"http://*/*", "tabs", "https://*/*"
],
"browser_action": {
"default_icon": "icon.jpg",
"default_popup":"popup.html"
},
"manifest_version": 2
}
popup.html
Linked style sheet for Browser action Popup
<html>
<head>
<link rel="stylesheet" href="styles.css"></link>
</head>
<body>
</body>
</html>
styles.css
used url() for image path
body{
width : 500px;
height: 500px;
background-image: url('img/icon.jpg');
}
Let me know if it still fails
EDIT 2)
For Injecting Images through content stuff
Solution a)
Using this converter, you convert your image to base64 strings and you can use them as
{ background-image: url(data:image/png;base64,iVBORw ........ };
Solution b)
The following code will not work because
{
background-image:url(chrome.extension.getURL('img/icon.jpg'));
}
chrome.extension.getURL() is undefined for css.
So, i used js for injection of background-images\any image URL's(Because they have dynamic URL's)
manifest.json
Simple json structure with all permissions defined for content scripts and css
{
"name": "My extension",
"version": "1.0",
"permissions": [
"http://*/*", "tabs", "https://*/*"
],
"content_scripts": [
{
"matches": ["<all_urls>"],
"js":["content.js"],
"css": ["styles.css"]
}
],
"web_accessible_resources": [
"img/icon.jpg"
],
"manifest_version": 2
}
content.js
As a trivial use case prepared a div and added background Image property
var newdiv = document.createElement('div');
newdiv.setAttribute("id", "moot450");
document.body.appendChild(newdiv);
document.getElementById('moot450').style.backgroundImage = "url(" + chrome.extension.getURL('img/icon.jpg') + ")";
styles.css
injected another css for refining injected div
#moot450{
position:absolute;
width:500px;
height:500px;
/*background-image:url(chrome-extension://faaligkhohdchiijdkcokpefpancidoo/img/icon.jpg);*/
}
OUTPUT
Screen shot taken from Google Page after injection
Let me know if you need more information or if it fails.

Resources