If You Must Use Flash
Generally speaking, my understanding is that Adobe no longer supports flash in Linux - but that the Google Chrome project has decided to integrate and support flash on their own. So Google Chrome would be the only browser that you can use at the moment out of the box, so to speak.
I have managed to get flash to work on other browsers from a recent install on an older 32 bit machine by using a flash-sse plugin (Shockwave Flash 11.1 r102). This build is made for chips that do not have SSE support. I don't know what machine you are using but this is important information.
This was not on an Ubuntu machine but an Arch Linux box running Gnome, but you should be able to find an older version of flash or flash-sse for Ubuntu.
What will happen is that the newer versions of Firefox (I have v27) will block older flash versions automatically with a security warning. You will have to click Activate ... and then Allow ... to view flash. Personally I prefer this as I don't like flash adverts streaming to my machine and using bandwidth.
The security risk, if any, can be mitigated somewhat by sending file locations to &>/dev/null, so that all data streaming in will be shredded on arrival.
[update] I have just installed Chromium v32+ and the above setup (Shockwave Flash 11.1 r102) works for Chromium too - without the grumbling that Firefox exhibits.
For Ubuntu you might be able to find a Debian package that will work. A good link to follow is https://wiki.debian.org/FlashPlayer. It seems that Flash 11 is the last version to work on Linux.
Otherwise Use HTML5
Alternatively, you can enable HTML5 instead of flash on any HTML5 capable browser (especially Chromium) by following this link https://www.youtube.com/html5 and clicking Request the HTML5 Player. From this point forward your Youtube videos and some others will play on any HTML5 capable browser, but I found on my older machine this was too resource intensive. On newer machines I don't think this will be a problem. This is where all streaming content is headed anyway and is why Adobe Flash will be phased out in the longer term.
Running an application in the background
The solution below will allow you to run firefox (or any other application) in the background, meaning: without a visible window. Nor will the application show in Dash as a running application:
If you pick Toggle Firefox however, the application will pop up immediately:
How it works
If the panel icon (indicator) starts up, it launches a new firefox
window, but immediately hides it (including possible existing firefox
windows) from the face of the earth, using xdotool
:
xdotool windowunmap <window_id>
This will not only hide the window, but also will hide the fact that firefox
is running at all, since the unity launcher acts on visibly existing windows.
- The indicator stores the id of all unmapped windows in
~/.config/hidden_windows
, to be mapped on the next time you choose Toggle Firefox from the menu.
The script
#!/usr/bin/env python3
import subprocess
import os
import signal
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('AppIndicator3', '0.1')
from gi.repository import Gtk, AppIndicator3
import time
app = "firefox"
winsdir = os.path.join(os.environ["HOME"], ".config/hidden_windows")
try:
os.mkdir(winsdir)
except FileExistsError:
pass
def checkruns(app):
try:
return subprocess.check_output(["pgrep", app]).decode("utf-8").strip()
except subprocess.CalledProcessError:
for w in os.listdir(winsdir):
if w.startswith(app):
os.remove(os.path.join(winsdir, w))
def get_currentwins(pid):
wins = subprocess.check_output(["wmctrl", "-lp"]).decode("utf-8").splitlines()
return [l.split()[0] for l in wins if pid in l]
def hide_currentwins(matches):
# open(os.path.join(winsdir, "windowlist"), "wt").write("\n".join(matches))
for w in matches:
open(os.path.join(winsdir, app+"_"+w), "wt")
subprocess.Popen(["xdotool", "windowunmap", w])
def run_app(app):
subprocess.Popen(app)
while True:
time.sleep(1)
pid = checkruns(app)
matches = get_currentwins(pid) if pid else None
if matches:
hide_currentwins(matches)
break
def restore_wins():
for w in [w for w in os.listdir(winsdir) if w.startswith(app)]:
wid = w.split("_")[-1]
subprocess.Popen(["xdotool", "windowmap", wid])
os.remove(os.path.join(winsdir, w))
def toggle_app(*args):
pid = checkruns(app)
if pid:
matches = get_currentwins(pid)
if matches:
hide_currentwins(matches)
else:
restore_wins()
else:
subprocess.Popen(app)
run_app(app)
class Indicator():
def __init__(self):
self.app = 'toggle_app'
self.indicator = AppIndicator3.Indicator.new(
self.app, app,
AppIndicator3.IndicatorCategory.OTHER)
self.indicator.set_status(AppIndicator3.IndicatorStatus.ACTIVE)
self.indicator.set_menu(self.create_menu())
def create_menu(self):
self.menu = Gtk.Menu()
item_toggle = Gtk.MenuItem('Toggle '+app)
item_toggle.connect("activate", toggle_app)
self.menu.append(item_toggle)
sep1 = Gtk.SeparatorMenuItem()
self.menu.append(sep1)
item_quit = Gtk.MenuItem('Quit')
item_quit.connect('activate', self.stop)
self.menu.append(item_quit)
self.menu.show_all()
return self.menu
def stop(self, source):
Gtk.main_quit()
Indicator()
signal.signal(signal.SIGINT, signal.SIG_DFL)
Gtk.main()
How to use
The script needs both wmctrl
and xdotool
sudo apt-get install wmctrl xdotool
Copy the script into an empty file, save it as firefox_bg.py
Test_run the script by the command:
python3 /path/to/firefox_bg.py
If all works fine, add it to Startup Applications: Dash > Startup Applications > Add. Add the command:
/bin/bash -c "sleep 10 && python3 /path/to/firefox_bg.py"
Alternatively, copy the code below into an empty file, save it as firefox_bgrunner.desktop
in ~/usr/share/applications
, log out and back in.
[Desktop Entry]
Type=Application
Exec=python3 /path/to/firefox_bg.py
Name=Firefox Webbrowser Background Runner
Icon=firefox
StartupWMClasss=nonsense
*The last line, StartupWMClasss=nonsense
is to make sure Firefox windows will appear under their own icon, not the one of the indicator
.
No need to mention that you have to edit the Exec=
line to reflect the real (absolute) path to where you stored firefox_bg.py
Then you will have the panel runner available from Dash:
Other applications?
I tested the same procedure with gnome-terminal
andThunderbird
(the latter usually not the quickest to startup), and it works perfectly:
To use with other applications, simply edit the line:
app = "firefox"
Note however that some applications seem to check if their attempt to create a window succeeded, and create a second one if the first one is unmapped. This happened to me with Inkscape
.
The script can even then perfectly be used though, but would need a small edit. If anyone ever might need to use it with Inkscape
, please leave a comment.
Best Answer
I think for chromium (not sure about chrome) you can edit that
~/.config/chromium/Default/User StyleSheets/Custom.css
At least I have and found it works.
For blocking the sponsored ads on startpage.com for example, edit/create the file and add:
Save it.
Run a search on startpage and see if the sponsored ads are displayed at the top.
Seems to work for me anyway.