aboutsummaryrefslogtreecommitdiffstats
path: root/internal/swextreload.go
diff options
context:
space:
mode:
authorTeddy Wing2023-11-20 00:32:49 +0100
committerTeddy Wing2023-11-20 00:32:49 +0100
commit34268da6c018a6c191836fe8c26576030cfde3e6 (patch)
tree4f891573733f207825e4c04a46c83adf0e385c79 /internal/swextreload.go
parentba83d5e8389638b4cbdbdbd024a9e294a422491d (diff)
downloadswextreload-34268da6c018a6c191836fe8c26576030cfde3e6.tar.bz2
swextreload: Ideas for problems sending messages
I'm sometimes having trouble sending messages to the extension pages. Trying out different things here but nothing appears to be cutting it just yet. It seems like there are times when we just don't get a response back or can't connect to a target for whatever reason, either in the initial extension reload step or in the tab reload. Also, since the delay for tab reloading appears to only be relevant for Manifest V3 extensions, I added a condition before sleeping.
Diffstat (limited to 'internal/swextreload.go')
-rw-r--r--internal/swextreload.go23
1 files changed, 17 insertions, 6 deletions
diff --git a/internal/swextreload.go b/internal/swextreload.go
index 1932b32..98bff1f 100644
--- a/internal/swextreload.go
+++ b/internal/swextreload.go
@@ -3,6 +3,7 @@ package swextreload
import (
"context"
+ "errors"
"fmt"
"log"
"strings"
@@ -66,15 +67,13 @@ func Reload(
}
if shouldReloadTab {
- time.Sleep(200 * time.Millisecond)
-
extensionURL := "chrome-extension://" + extensionIDs[0] + "/"
var firstExtensionTarget *target.Info
for _, target := range targets {
- // for i := len(targets) - 1; i >= 0; i-- {
+ // for i := len(targets) - 1; i >= 0; i-- {
- logDebugf("A target: %#v", target)
+ // logDebugf("A target: %#v", target)
if strings.HasPrefix(target.URL, extensionURL) {
firstExtensionTarget = target
@@ -89,11 +88,23 @@ func Reload(
}
}
+ if firstExtensionTarget == nil {
+ // TODO: continue loop until target != null
+ return errors.New("swextreload: can't reload tab, no target available")
+ }
+
+ isMV2 := isExtensionManifestV2(firstExtensionTarget)
+
+ // TODO: Only do this in MV3.
+ if !isMV2 {
+ time.Sleep(200 * time.Millisecond)
+ }
+
err = reloadTab(
allocatorContext,
extensionIDs[0],
firstExtensionTarget,
- isExtensionManifestV2(firstExtensionTarget),
+ isMV2,
)
if err != nil {
return err
@@ -151,7 +162,7 @@ func reloadTab(
isExtensionManifestV2 bool,
) error {
ctx, cancel := chromedp.NewContext(ctx)
- defer cancel()
+ // defer cancel()
logDebugf("Reload tab (Manifest V2: %t)", isExtensionManifestV2)