Skip to content

Commit

Permalink
Allow Firefox prefs to be set in config.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
tombh committed Jun 18, 2019
1 parent 2b97b29 commit 931cc1c
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 111 deletions.
1 change: 1 addition & 0 deletions interfacer/src/browsh/comms.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func webSocketServer(w http.ResponseWriter, r *http.Request) {
go webSocketWriter(ws)
go webSocketReader(ws)
sendConfigToWebExtension()
setDefaultFirefoxPreferences()
if !viper.GetBool("http-server-mode") {
sendTtySize()
}
Expand Down
4 changes: 4 additions & 0 deletions interfacer/src/browsh/config_sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ use-existing = false
# Launch Firefox in with its visible GUI window. Useful for setting up the Browsh profile.
with-gui = false
# Config that you might usually set through Firefox's 'about:config' page
[firefox-config]
# "privacy.resistFingerprinting" = true
[tty]
# The time in milliseconds between requesting a new TTY-sized pixel frame.
# This is essentially the frame rate for graphics. Lower values make for smoother
Expand Down
22 changes: 13 additions & 9 deletions interfacer/src/browsh/firefox.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,14 @@ func installWebextension() {
// Set a Firefox preference as you would in `about:config`
// `value` needs to be supplied with quotes if it's to be used as a JS string
func setFFPreference(key string, value string) {
var args map[string]interface{}
var script string
sendFirefoxCommand("Marionette:SetContext", map[string]interface{}{"value": "chrome"})
script := fmt.Sprintf(`
script = fmt.Sprintf(`
Components.utils.import("resource://gre/modules/Preferences.jsm");
prefs = new Preferences({defaultBranch: false});
prefs.set("%s", %s);`, key, value)
args := map[string]interface{}{"script": script}
prefs = new Preferences({defaultBranch: "root"});
prefs.set("%s", %s);`, key, value)
args = map[string]interface{}{"script": script}
sendFirefoxCommand("WebDriver:ExecuteScript", args)
sendFirefoxCommand("Marionette:SetContext", map[string]interface{}{"value": "content"})
}
Expand All @@ -271,10 +273,13 @@ func sendFirefoxCommand(command string, args map[string]interface{}) {
readMarionette()
}

func setDefaultPreferences() {
func setDefaultFirefoxPreferences() {
for key, value := range defaultFFPrefs {
setFFPreference(key, value)
}
for key, value := range viper.GetStringMapString("firefox-config") {
setFFPreference(key, value)
}
}

func beginTimeLimit() {
Expand All @@ -287,16 +292,13 @@ func beginTimeLimit() {
quitBrowsh()
}

// Note that everything executed in and from this function is not covered by the integration
// tests, because it uses the officially signed webextension, of which there can be only one.
// We can't bump the version and create a new signed webextension for every commit.
// Careful what you change here as it isn't tested during CI
func setupFirefox() {
go startHeadlessFirefox()
if *timeLimit > 0 {
go beginTimeLimit()
}
firefoxMarionette()
setDefaultPreferences()
installWebextension()
}

Expand All @@ -306,10 +308,12 @@ func StartFirefox() {
if IsTesting {
writeString(0, 17, "TEST MODE", tcell.StyleDefault)
go startWERFirefox()
firefoxMarionette()
} else {
setupFirefox()
}
} else {
firefoxMarionette()
writeString(0, 16, "Waiting for a user-initiated Firefox instance to connect...", tcell.StyleDefault)
}
}
Expand Down
11 changes: 0 additions & 11 deletions package-lock.json

This file was deleted.

2 changes: 1 addition & 1 deletion webext/contrib/firefoxheadless.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ if [[ "$1" = "kill" ]]; then
fi
else
FIREFOX_BIN=${FIREFOX:-firefox}
$FIREFOX_BIN --headless "$@"
$FIREFOX_BIN --headless --marionette "$@"
fi
Loading

0 comments on commit 931cc1c

Please sign in to comment.