Change icon of running firefox profile
Asked Answered
S

4

8

I'm using Win7 but looking for a cross os solution, but this isnt even working in my Win7. I'm trying to change the icon of just the current profile. So what i did was:

  1. I created shortcut of firefox.exe and moved it to my documents
  2. right click on this shortcut and then changed icon
  3. but in firefox the taskbar shows normal firefox icon and so does the top left icon (see attached image plz)

How can I change this icon?

Thanks

enter image description here

Here's another topic i made on ask.m.o trying to ask the same thing: https://ask.mozilla.org/question/725/custom-icon-per-profile/

Scoville answered 2/6, 2014 at 22:39 Comment(1)
This topic got 1000+ views I just got notified. I resolved this on Windows, Mac, and almost on Linux. If anyone wants help doing the same definitely post a message here and I'll show it to you. If you can help on the Linux part too that would be awesome!Scoville
B
10

As of Firefox 57, this is not possible from an extension.

WebExtensions do not permit the window icon to be changed from an extension.

Prior to Firefox 57 (or non-release versions w/ legacy add-ons)

The combination of the title of your question and the text of your question make it unclear what you desire to accomplish.

If your goal is to dynamically change the window icon of a currently running Firefox process then you will need to follow something along the lines of the second or third method listed in nmaier's answer.

If you goal is to always have a different, static icon used for the primary Firefox windows for a specific profile, that is quite easy.

You will need icon files of the appropriate format for each architecture for which you desire this to work.

The following assumes Windows, it is easily expanded to other architectures by including an icon file with the same name, but appropriate file extension and format.

Create a simple overlay, extracted extension. You will need a minimum of 2 files:

  1. <extension-dir>instal.rdf
  2. <extension-dir>\chrome\icons\default\main-window.ico

Example, fully functional, install.rdf:

<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:em="http://www.mozilla.org/2004/em-rdf#">
    <Description about="urn:mozilla:install-manifest">
        <em:id>[email protected]</em:id>
        <em:version>1.0.0</em:version>
        <em:name>Window icon change</em:name>
        <em:description>Change the Firefox main window icon.</em:description>
        <em:creator>Makyen</em:creator>
        <em:unpack>true</em:unpack>
        <em:targetApplication>
            <Description>
                <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
                <em:minVersion>3.0a1</em:minVersion>
                <em:maxVersion>43.0a1</em:maxVersion>
            </Description>
        </em:targetApplication>
    </Description>
</RDF>

NOTE: The "<extension-dir>\chrome\icons\default\" directory is different than the one in the response by nmaier. In that answer the "icons" and "default" directories reversed and will be non-functional.

You will probably want an additional file:
<extension-dir>chrome.manifest
The chrome.manifest file is not required. However, not having it may result in a single line being printed to the error/browser console (if you even have that open). If the chrome.manifest file exists, even if zero length, there will be no complaint in the console that the file could not be read.

Install the extension. The easy way to do this is to create a zip file with those three files; then change the file extension to .xpi; then drag and drop it onto a Firefox window running the profile in which you desire it to be installed.

You can expand this to include icons for whatever sub-windows you desire. You will need to determine the ID for each sub-window. The icon file name is just the window ID with the appropriate extension for an icon in the architectures you desire. "main-window" is just the ID for the main Firefox browser window.

Creating an extension to test this took less than 5 minutes. You should find it reasonably easy to accomplish.

This assumes that there is not a custom main-window icon located at (Windows, default install location):
C:\Program Files\Mozilla Firefox\browser\chrome\icons\default
as that directory is for all profiles and is searched first.

This will not work if the extension is either restartless or extractionless.

You can find a brief amount of information about window icons on MDN. nmaier mentions the docs talking about bundles. When talking about Mozilla add-ons, a bundle is your add-on package.

The icon file(s) will be at (Windows):
<profile dir>\extensions\<extension-dir>\chrome\icons\default*
Once the extension is installed, you can change it/them manually without re-installing, if desired.

Add-ons created to solve this

Based on the discussion in the comments, I created a Firefox Add-on to allow setting the window icons for the profile. It is much expanded upon the 5 minute add-on mentioned in the comments. The addition is entirely in a UI for the options dialog for selecting the icon to use and assigning it to the various different windows Firefox opens. You can get it from Mozilla Add-ons under Change Profile's Window Icons. Unfortunately, it's not possible for that add-on to function as of Firefox 48 which requires add-ons to be signed. To dynamically change the icon requires changing files which must be signed. Thus it's not possible to dynamically change the icon with add-on signing required.

Instead I created a few add-ons which statically change the window icon. You can find them on AMO.

Bulwerlytton answered 25/6, 2014 at 0:3 Comment(10)
I admit my question was unclear on the dynamic or not part. I like your answer. Can you please link an example of the 5 minute add-on that uses this. Thanks. I'm going to accept this solution too.Scoville
Yep, nice write-up on my point 1. However, like I stated, you'll run into trouble with this when the Firefox distribution provides default icons for a window type, which some *nix distributions do (or used to do?). Then you cannot provide another icon via an extension. @Noitidart, BTW you cannot actually "accept this solution too", only switch the accepted answer, which is what you did. ;)Meathead
@Meathead Ah bah. I gave you like a thousand points anyways, I'm going to try to lure this guy in as a SO answerer who has good spelling and writes out posts like you, by giving him points. :P (even though I used your method from that SetClassLongPtr example which is better than your below method :P )Scoville
@Scoville I would be happy to provide a link to such an extension. However, that immediately brings up the question: What icon do you desire included? If I am providing a link including the icon, it needs to have an appropriate license for me to do so (which is why I don't just link with what I tested).Bulwerlytton
Thanks man. Can you say for educational purposes and would that make things ok? lol if not can you please ues this icon here: IconArchive :: Blue Bits Icons by Icojam - Puzzle [Download ICO]Scoville
You should be able to get it from mediafire.com/download/7m2gnqwd5ef644h/…Bulwerlytton
I did change the name and description in the install.rdf from what I had provided above. I have now updated that also. The changes are just cosmetic. Once downloaded, you should be able to drag-and-drop the [email protected] file onto a Firefox window running the profile you desire to change. Doing so worked fine for me. A restart of Firefox will be required. You can easily change the icon by just replacing the <profile dir>\extensions\[email protected]\chrome\icons\defaultmain-window.ico file. Please keep me informed if you have any problems.Bulwerlytton
I added a link in the answer to an enhanced version of the extension begun in these comments. The extension is Change Profile's Window Icons at Mozilla Add-ons.Bulwerlytton
Oh man I missed that demo addon you uploaded!! Thanks I'm going to test it tomorrow on linux and mac :) thanks man! You gotta @ my name so i can see these comments please :P otherwise i get no notification :(Scoville
I get this “this addon could not be installed, because it appears to be corrupt”, when I drag the file into firefox.Buoy
M
4

Well, there are some ways that spring to mind, but all with their own issues:

  1. Using Window Icons provided by an add-on you install into the profile (the docs talk about bundles, but add-on can also use this technique). The add-on must be em:unpack and have the icon(s) in chrome/default/icons exactly. It is possible that the Firefox in question has an own set of icons bundled in the $appdir/chrome/default/icons, in particular on *nix and since they are checked first, they will be used instead of the add-on provided add-ons. So while this approach works for custom add-on windows, it might not for built-in ones.
  2. Copy and patch Firefox itself, aka. the sledgehammer approach. Different for each platform (e.g. under Windows you'd have to swap out the icon resource of the firefox.exe).
  3. Create a tool that will switch out the icons of a running window. There is no code to do so in Firefox that would be accessible from javascript, so you need to go binary and platform-specific, e.g. WM_SETICON on Windows.

Edit 1: Actually, thinking more about it, I'd install an add-on with some platform-specific js-ctypes code that would then switch out the icons, e.g. the already mentioned WM_SETICON on Windows.

Usually you'll need a window handle for the platform APIs, which Firefox refuses to provide to JS. But as a workaround for that:

  1. Store the window title.
  2. Set the window title to a new uuid.
  3. Call a platform API to find the new uuid titled window handle (FindWindow on Windows). mintrayr uses this scheme for Windows/Gnome(GTK/GDK), also not in js-ctypes.
  4. Restore the window title.
  5. Load/transform the icon file to something the platform supports (HICON on windows). I once had a patch somewhere on bugzilla that enabled loading of arbitrary images as window icons FWIW, but let it slide. Should be still somewhere and could give pointers.
  6. Switch the icon using the obtained handle. E.g. Sending two WM_SETICON for small/big icon on Windows.

Edit 2 Turns out nsIBaseWindow exposes a nativeHandle these days, as I learned from your other question. so the window-title–hack isn't needed any longer. However, nativeHandle might be an 64-bit pointer, which isn't really supported in JS land without some trickery... Better not parseInt it... Also js numbers are floats.

ctypes.voidptr_t(ctypes.UInt64(nativeHandle)) should work, though.

Meathead answered 3/6, 2014 at 2:0 Comment(10)
Wow! Thanks so much for this detail man i thought it was hopeless as no one gave me replies else where. Can you please elaborate on #2 please. I think that's a good idea because i need to copy and give it a -P -profileName so if user pins it to taskbar then closes FF then launches again from that pin it will launch into right profile.Scoville
Well, you rewrite the binary, e.g. modify bits and bytes in firefox.exe or whatever a platform uses. There are various tools that let you edit icon resources in exe and similar tools for non-Windows platforms. Please note that on Windows binary is Authenticode-signed, so you might also want to remove the signature after patching the binary.Meathead
Ohhh yikes this is not possible for my restartless addon huh? I'm trying to plug into profilist, please see this image: github.com/evacchi/firefox-custom-badge/issues/1Scoville
Also in #1 what is the way to do it for mac os?Scoville
Re #1 mac: OS X does not actually have window icons, just .app icons, which you cannot change.Meathead
Wow man thanks so much man your answers are sooooo detailed you spend so much time on them you deserve like 5 points each question. I think I'll try that ctypes approach you mentioned thanks man!Scoville
Hey man here's my work Re #3 GitHub - Gist :: Noitidart / _ff-addon-snippet-ChangeWindowIcon.js - Rev1. It's got some issues I need help with though, I'll make a separate topic for that.Scoville
Left a few comments on your gist.Meathead
Let us continue this discussion in chat.Scoville
Thanks man for that edit. If it's UInt64 can't I just set the ctypes paramter to that. So what I did was: var SendMessage = user32.declare('SendMessageW', ctypes.winapi_abi, ctypes.uintptr_t, ctypes.uint64_t, then var targetWindow_handle = nativeHandle; I got the error: Exception: expected type uint64_t, got "0x1070140"Scoville
A
1

On Mac OS X, this Firefox plugin will do just that: https://addons.mozilla.org/en-US/firefox/addon/fosx-label/. Also on GitHub: https://github.com/jf/fosx-label. Thanks to Noitidart for pointing out this very useful plugin.

Tested on Yosemite 10.10.5 and it works perfectly!

Alkalosis answered 11/9, 2015 at 19:34 Comment(2)
Excellent job man!! If you are available and have time, you should hook up this method: gist.github.com/Noitidart/6e39b7a0b2c3419a1165 i am implementing a feature like that with Profilist, the complex part was making the icns (youtube.com/watch?v=QXV7N74IXYc and github.com/Noitidart/Icon-Container-Generator ), but for simplicity you can just use a single png.Scoville
The plugin doesn't seem to work with the latest version of FireFox (version 54, 2017). Is there another technique?Pasteup
T
0

This is how I did it in Linux Mint 21.3 cinnamon:

I created a file for each firefox profile in ~/.local/share/applications/firefox-work-script.sh

This file contains this small script:

bash
#!/bin/bash

# source_dir contains the icons for work profile (one png file named "default128.png" is enough)
source_dir="/opt/firefox/browser/chrome/icons/default/work/"

# target_dir is where firefox keeps it's default icons. move "default128.png" into a folder named "default" in the target folder and remove the rest.
target_dir="/opt/firefox/browser/chrome/icons/default/"

cp -f ${source_dir}* ${target_dir}

# this line will run Firefox with profile "work". change it to your own profile name.
/opt/firefox/firefox -p work

Create respectful icon for each profile and put them in their respectful directory. in the above example, the directory name is work. Size of the icon should be less than 256x256. but regardless of the actual size, the name of the file should be default128.png. taskbar will resize the icon to fit in the taskbar but depending on taskbar size it might not look good. My taskbar size is thin so I change my icon size to 48x48 to keep the quality at best. but it's not necessary.

Final folder structure:

/opt/firefox/browser/chrome/icons/default/
                                  ├── default128.png
                                  ├── default/
                                  │   └── default128.png
                                  ├── game/
                                  │   └── default128.png
                                  └── work/
                                      └── default128.png

Then in the .desktop file of firefox (e.g. firefox-work-profile.desktop. The shortcut file that runs firefox and usually is in the same folder that we created the above script) I have this:
NOTE: change the "YOUR_USER_NAME" to your user name. Obviously.

[Desktop Entry]
Name=Firefox Work
Exec=/home/YOUR_USER_NAME/.local/share/applications/firefox-work-script.sh
Comment=Mozilla Firefox Work Profile
Icon=/opt/firefox/browser/chrome/icons/default/work/default128.png
StartupNotify=true
Terminal=false
Type=Application
Categories=Network;WebBrowser;
MimeType=application/pdf;application/rdf+xml;application/rss+xml;application/xhtml+xml;application/xhtml_xml;application/xml;image/gif;image/jpeg;image/png;image/webp;text/html;text/xml;x-scheme-handler/http;x-scheme-handler/https;
Actions=new-window;new-private-window;

[Desktop Action new-window]
Name=New Window
Exec=/opt/firefox/firefox -p work

[Desktop Action new-private-window]
Name=New Incognito Window
Exec=/opt/firefox/firefox -p work -private

And that's it. Except for these two things:

1- Important: I needed to delete all theme related firefox icons for the theme that was active in my theme settings (mine was Mint-Y). I searched for firefox keyword in /usr/share/icons/Mint-Y/apps/ and deleted them all.

2- Remember to do all of the above for your default profile too since you will have at least two profiles and default profile needs it's own icon.

This was the general idea and can be used differently (probably).

Thwart answered 9/5 at 18:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.