Skip to content

Commit

Permalink
fix: Don't load startup URL in HTTP Server mode
Browse files Browse the repository at this point in the history
I think this is the source of a long-standing issue in the HTTP Server
where it would just freeze after a certain period of time. Every
successful page load, wether it was explicitly requested as a raw-text
request or not, attempts to send a raw text payload on page load. So I
think the automatic default home page startup loading was confusing
things.

Fixes #207
  • Loading branch information
tombh committed Jul 16, 2022
1 parent 1f20113 commit aaea254
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
7 changes: 4 additions & 3 deletions interfacer/src/browsh/browsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ var (
********///////////////
***********************`
// IsTesting is used in tests, so it needs to be exported
IsTesting = false
logfile string
_ = pflag.Bool("version", false, "Output current Browsh version")
IsTesting = false
IsHTTPServerMode = false
logfile string
_ = pflag.Bool("version", false, "Output current Browsh version")
)

func setupLogging() {
Expand Down
4 changes: 3 additions & 1 deletion interfacer/src/browsh/comms.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ func webSocketServer(w http.ResponseWriter, r *http.Request) {
// work. So we do it here instead.
validURL := viper.GetStringSlice("validURL")
if len(validURL) == 0 {
sendMessageToWebExtension("/new_tab," + viper.GetString("startup-url"))
if !IsHTTPServerMode {
sendMessageToWebExtension("/new_tab," + viper.GetString("startup-url"))
}
} else {
for i := 0; i < len(validURL); i++ {
sendMessageToWebExtension("/new_tab," + validURL[i])
Expand Down
1 change: 1 addition & 0 deletions interfacer/src/browsh/raw_text_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type rawTextResponse struct {
// it will return:
// `Something `
func HTTPServerStart() {
IsHTTPServerMode = true
StartFirefox()
go startWebSocketServer()
Log("Starting Browsh HTTP server")
Expand Down
15 changes: 10 additions & 5 deletions webext/src/background/tab_commands_mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,16 @@ export default MixinBase =>
}

_rawTextRequest(incoming) {
let payload = {
json: JSON.stringify(incoming),
request_id: this.request_id
};
this.sendToTerminal(`/raw_text,${JSON.stringify(payload)}`);
// I think the only reason that a tab would send a raw text payload is the
// automatic startup URL loading, which should now be disabled for HTTP Server
// mode.
if (this.request_id) {
let payload = {
json: JSON.stringify(incoming),
request_id: this.request_id
};
this.sendToTerminal(`/raw_text,${JSON.stringify(payload)}`);
}
this._tabCount(count => {
if (count > 1) {
this.remove();
Expand Down

0 comments on commit aaea254

Please sign in to comment.