fix: Don't load startup URL in HTTP Server mode

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
This commit is contained in:
Thomas Buckley-Houston 2022-07-16 17:06:46 -04:00
parent 1f20113bc0
commit aaea254f0d
4 changed files with 18 additions and 9 deletions

View File

@ -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() {

View File

@ -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])

View File

@ -66,6 +66,7 @@ type rawTextResponse struct {
// it will return:
// `Something `
func HTTPServerStart() {
IsHTTPServerMode = true
StartFirefox()
go startWebSocketServer()
Log("Starting Browsh HTTP server")

View File

@ -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();