This repository has been archived by the owner on Dec 7, 2022. It is now read-only.
/
reset-browser-preferences
executable file
·75 lines (64 loc) · 3.95 KB
/
reset-browser-preferences
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
# NOTE: Depends on the wmctrl, sqlite3 and jq packages. None of these are typically installed out of the box on any
# debian flavor. Of course, also depends on chromium-browser or google-chrome being present.
#
# Resets Chromium or Chrome browser preferences and then modfies the default to my liking:
# - Delete all search engines.
# - Set DuckDuckGo as the default search engine.
# - Turn off 'Use a web service to help resolve navigation errors'.
# - Turn off 'Use a prediction service to load pages more quickly'.
# - Turn on 'Send a "Do Not Track" request with your browsing traffic'.
# - Turn off 'Autofill'.
# - Turn off 'Manage passwords'.
# - Set 'Languages' to English and German.
# - Set 'Spell check' to English and German.
# - Turn off 'Continue running background apps when Chromium is closed'.
set -o errexit
set -o nounset
set -o pipefail
if [[ ($# -ne 1) || (("$1" != "chromium-browser") && ("$1" != "google-chrome")) ]]; then
echo "Error: The only argument must either be chromium-browser or google-chrome."
exit 1
fi
if [ "$1" == "chromium-browser" ]; then
title="Chromium"
master_preferences=/usr/lib/chromium-browser/master_preferences
config_folder=~/.config/chromium
else
title="Chrome"
master_preferences=/opt/google/chrome/master_preferences
config_folder=~/.config/google-chrome
fi
# Close browser (if it's currently running) and wait for it to shut down completely.
# When it is not currently running, wmctrl ends with a non-zero exit code. If it weren't for the || true bit,
# a non-zero exit code would abort the script (due to errexit).
wmctrl -c $title || true
sleep 3
# Delete all config data
rm -rf $config_folder
# By default, at least on Ubuntu, a newly installed browser displays the welcome page on its first run. That page seems
# to pause preferences initialization such that the "keywords" table in the $config_folder/Default/Web\ Data database
# stays empty until the user interacts with the page (e.g. by clicking "No thanks") or opens a new tab. To avoid the
# necessity of the user having to interact in any way, we change the master_preferences file of the installation such
# that the welcome page is no longer displayed and initialization runs to completion.
if [ ! -f "$master_preferences" ]; then
echo "{ }" | sudo tee $master_preferences
fi
# This currently works to prevent first run interaction for Chromium, but apparently it's not currently possible to
# avoid first run interaction with Chrome, see https://bugs.chromium.org/p/chromium/issues/detail?id=418093.
cat $master_preferences | jq '.first_run_tabs=["http://new_tab_page"]' >adapted-master-preferences.json
sudo mv adapted-master-preferences.json $master_preferences
# Restart browser and wait for the config initialization to finish
$1 &
sleep 20
# Close browser and wait for it to shut down completely
wmctrl -c $title
sleep 3
# Delete all search engines
sqlite3 $config_folder/Default/Web\ Data "delete from keywords;"
# Modify most of the preferences to my liking (see comments at the top for details)...
cat $config_folder/Default/Preferences | jq '.browser.has_seen_welcome_page=true | .alternate_error_pages.enabled=false | .autofill.enabled=false | .credentials_enable_service=false | .default_search_provider_data.template_url_data={ "keyword": "duckduckgo.com", "short_name": "DuckDuckGo", "suggestions_url": "https://duckduckgo.com/ac/?q={searchTerms}&type=list", "url": "https://duckduckgo.com/?q={searchTerms}&t=canonical" } | .enable_do_not_track=true | .intl.accept_languages="en-US,en,de-CH,de" | .net.network_prediction_options=2 | .search.suggest_enabled=true | .spellcheck.dictionaries += ["en-US", "de"] | .translate_blocked_languages += ["de"]' >adapted-preferences.json
mv adapted-preferences.json $config_folder/Default/Preferences
# ...except for background mode, which sits in a different file
cat $config_folder/Local\ State | jq '.background_mode.enabled=false' >adapted-local-state.json
mv adapted-local-state.json $config_folder/Local\ State