browser: an extension older than magpie's is to be reloaded, says the sheet and the agent
magpie rewrites the extension's folder when an older one connects, but Chrome runs what it loaded until the extension is reloaded on chrome://extensions or the browser starts again, so a user who never does either stays on the old code. Now that is said: - Library → Magpie Browser: under "Connected to your browser · 0.1.8" a line says "Magpie Browser 0.1.9 is ready: reload Magpie Browser on chrome://extensions (edge://extensions in Edge)." Looked at from another computer (the zip install), it says to download it again, unzip it over the old folder and reload it. /api/library/browser has outdated. - The agent: the first browser answer on such a connection starts with a line telling it to have the user reload it (or download it again, for one connected with a gateway key). Once a connection. The extension still isn't made to reload itself: an unpacked one that calls chrome.runtime.reload() doesn't come back (the finding in browser.go's hello). The fake extension in the gateway's tests now says magpie's own version (it said 0.1.0, which every test would now be told about). Run (on mote): - internal/gateway TestBrowser* (new TestBrowserSaysTheExtensionIsOlder, TestBrowserSaysNothingOfACurrentExtension), ok. - internal/gui TestBrowser* (new TestBrowserStateOutdated), ok. - GUI: library-browser-setup, library-browser-away, library-browser-ask, browser-access, i18n-keys in Chromium and WebKit, every language, at 1100 and 420 wide: 127 of 128. The red is i18n-keys "a plugin's words are its own" for three keys this change doesn't touch, red on main and filed (#5332, #5482, #5426). - go vet for darwin, linux (nogui) and windows; gofmt -l clean. Broken by hand: - the once-a-connection check removed: TestBrowserSaysTheExtensionIsOlder red ("s1's next answer" has the note again). - the sheet's line never shown: library-browser-setup red, 20 of 20. - Outdated without Connected: TestBrowserStateOutdated red. Not tried: the whole GUI suite before this push (run next), and a real Chrome with an older extension loaded by hand.
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/coder/websocket"
|
||||
@@ -103,7 +104,10 @@ type browserConn struct {
|
||||
// calls (their pages read, and pages of theirs fed back).
|
||||
own bool
|
||||
since time.Time
|
||||
wmu sync.Mutex
|
||||
// told: an agent was told this extension is older than magpie's
|
||||
// (browserOlder), once a connection
|
||||
told atomic.Bool
|
||||
wmu sync.Mutex
|
||||
}
|
||||
|
||||
// browserName is the browser a User-Agent names, with its major version:
|
||||
@@ -634,11 +638,30 @@ func (s *Server) browserMCPCall(r *http.Request, m mcpMessage) (any, map[string]
|
||||
}
|
||||
}
|
||||
}
|
||||
return said(result), nil
|
||||
return s.browserOlder(session, said(result)), nil
|
||||
}
|
||||
return nil, map[string]any{"code": -32601, "message": "method not found: " + m.Method}
|
||||
}
|
||||
|
||||
// browserOlder puts a word before result, once a connection, when the
|
||||
// extension is older than this magpie's: its folder has the new one, but
|
||||
// the browser runs what it loaded until the extension is reloaded or the
|
||||
// browser starts again, so the agent tells the user.
|
||||
func (s *Server) browserOlder(session string, result map[string]any) map[string]any {
|
||||
c := s.browser.forSession(session)
|
||||
if c == nil || !browserext.Older(c.version, browserext.Version()) || !c.told.CompareAndSwap(false, true) {
|
||||
return result
|
||||
}
|
||||
how := "it is reloaded on chrome://extensions (edge://extensions in Edge): magpie has put the new one in its folder already"
|
||||
if c.key != "" {
|
||||
how = "it is downloaded again from magpie's Library → Magpie Browser, unzipped over the old folder and reloaded on chrome://extensions (edge://extensions in Edge)"
|
||||
}
|
||||
note := fmt.Sprintf("Tell the user: Magpie Browser in their browser is %s and magpie has %s, which the browser doesn't run until %s.", c.version, browserext.Version(), how)
|
||||
content, _ := result["content"].([]any)
|
||||
result["content"] = append([]any{map[string]any{"type": "text", "text": note}}, content...)
|
||||
return result
|
||||
}
|
||||
|
||||
// browserPicture is a picture of session's window (base64), or why there
|
||||
// is none.
|
||||
func (s *Server) browserPicture(r *http.Request, session string) (data, why string) {
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/browserext"
|
||||
)
|
||||
|
||||
// An extension older than magpie's keeps running its old code until it is
|
||||
// reloaded, though magpie rewrote its folder: the first answer on that
|
||||
// connection tells the agent to have the user reload it (or, for one
|
||||
// connected with a key, download it again), and only the first.
|
||||
func TestBrowserSaysTheExtensionIsOlder(t *testing.T) {
|
||||
fresh(t)
|
||||
t.Setenv("MAGPIE_ADDR", "")
|
||||
t.Setenv("MAGPIE_PUBLIC_URL", "")
|
||||
t.Setenv("MAGPIE_TRUST_PROXY", "")
|
||||
s := New()
|
||||
const testPeer = "X-Test-Peer"
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if p := r.Header.Get(testPeer); p != "" {
|
||||
r.RemoteAddr, r.Host = p, "192.0.2.1:3425"
|
||||
r.Header.Del(testPeer)
|
||||
}
|
||||
lanGuard(s.Handler()).ServeHTTP(w, r)
|
||||
}))
|
||||
t.Cleanup(srv.Close)
|
||||
page := func(_, _, _ string, _ map[string]any) any {
|
||||
return map[string]any{"content": []any{map[string]any{"type": "text", "text": "Page: Example"}}}
|
||||
}
|
||||
h := lanGuard(s.Handler())
|
||||
call := func(addr string, hdr ...string) []string {
|
||||
t.Helper()
|
||||
m := readImageReply(t, browserPost(h, addr, imageToolCall("browser_navigate", map[string]any{"url": "example.com"}), hdr...))
|
||||
if m.Result.IsError {
|
||||
t.Fatalf("an error: %+v", m.Result.Content)
|
||||
}
|
||||
var all []string
|
||||
for _, c := range m.Result.Content {
|
||||
all = append(all, c.Text)
|
||||
}
|
||||
return all
|
||||
}
|
||||
const old = "0.0.1"
|
||||
if !browserext.Older(old, browserext.Version()) {
|
||||
t.Fatalf("%s isn't older than %s", old, browserext.Version())
|
||||
}
|
||||
|
||||
fakeExtensionVersion(t, srv.URL, "", nil, "Chrome/141", old, page)
|
||||
browserConnected(t, s)
|
||||
got := call("127.0.0.1:5000", BrowserSessionHeader, "s1")
|
||||
if len(got) != 2 || got[1] != "Page: Example" || !strings.Contains(got[0], old) || !strings.Contains(got[0], browserext.Version()) ||
|
||||
!strings.Contains(got[0], "reloaded on chrome://extensions") || strings.Contains(got[0], "downloaded again") {
|
||||
t.Fatalf("the first answer: %q", got)
|
||||
}
|
||||
// once a connection, whichever session asks next
|
||||
for _, session := range []string{"s1", "s2"} {
|
||||
if got := call("127.0.0.1:5000", BrowserSessionHeader, session); len(got) != 1 || got[0] != "Page: Example" {
|
||||
t.Fatalf("%s's next answer: %q", session, got)
|
||||
}
|
||||
}
|
||||
|
||||
// connected with a key, from elsewhere: downloaded again
|
||||
keys, secrets := newCaller(t, "Host browser")
|
||||
fakeExtensionVersion(t, srv.URL, secrets[0], http.Header{testPeer: {"172.17.0.1:40000"}}, "Chrome/141", old, page)
|
||||
for deadline := time.Now().Add(10 * time.Second); len(s.browser.all(keyedSession(keys[0].ID, "x"))) < 1; time.Sleep(5 * time.Millisecond) {
|
||||
if time.Now().After(deadline) {
|
||||
t.Fatal("the keyed extension never connected")
|
||||
}
|
||||
}
|
||||
mine := []string{"Authorization", "Bearer " + secrets[0], BrowserSessionHeader, "s1"}
|
||||
got = call("172.17.0.1:40000", mine...)
|
||||
if len(got) != 2 || !strings.Contains(got[0], "downloaded again from magpie's Library → Magpie Browser") {
|
||||
t.Fatalf("the keyed one's first answer: %q", got)
|
||||
}
|
||||
if got := call("172.17.0.1:40000", mine...); len(got) != 1 {
|
||||
t.Fatalf("the keyed one's next answer: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
// One as new as magpie's is never told about.
|
||||
func TestBrowserSaysNothingOfACurrentExtension(t *testing.T) {
|
||||
fresh(t)
|
||||
s := New()
|
||||
srv := httptest.NewServer(lanGuard(s.Handler()))
|
||||
t.Cleanup(srv.Close)
|
||||
fakeExtension(t, srv.URL, func(_, _, _ string, _ map[string]any) any {
|
||||
return map[string]any{"content": []any{map[string]any{"type": "text", "text": "Page: Example"}}}
|
||||
})
|
||||
browserConnected(t, s)
|
||||
m := readImageReply(t, browserPost(lanGuard(s.Handler()), "127.0.0.1:5000", imageToolCall("browser_navigate", map[string]any{"url": "example.com"}), BrowserSessionHeader, "s1"))
|
||||
if len(m.Result.Content) != 1 || m.Result.Content[0].Text != "Page: Example" {
|
||||
t.Fatalf("%+v", m.Result.Content)
|
||||
}
|
||||
}
|
||||
@@ -48,6 +48,12 @@ func fakeExtensionAs(t *testing.T, base, agent string, answer func(id, session,
|
||||
// fakeExtensionWith is fakeExtensionAs given key (as the extension's popup
|
||||
// is) and sending hdr.
|
||||
func fakeExtensionWith(t *testing.T, base, key string, hdr http.Header, agent string, answer func(id, session, tool string, args map[string]any) any) {
|
||||
t.Helper()
|
||||
fakeExtensionVersion(t, base, key, hdr, agent, browserext.Version(), answer)
|
||||
}
|
||||
|
||||
// fakeExtensionVersion is fakeExtensionWith saying it is version.
|
||||
func fakeExtensionVersion(t *testing.T, base, key string, hdr http.Header, agent, version string, answer func(id, session, tool string, args map[string]any) any) {
|
||||
t.Helper()
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
h := http.Header{"Origin": {browserext.Origin}}
|
||||
@@ -65,7 +71,7 @@ func fakeExtensionWith(t *testing.T, base, key string, hdr http.Header, agent st
|
||||
}
|
||||
done := make(chan struct{})
|
||||
t.Cleanup(func() { cancel(); c.CloseNow(); <-done })
|
||||
if err := c.Write(ctx, websocket.MessageText, []byte(`{"type":"hello","version":"0.1.0","agent":"`+agent+`"}`)); err != nil {
|
||||
if err := c.Write(ctx, websocket.MessageText, []byte(`{"type":"hello","version":"`+version+`","agent":"`+agent+`"}`)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
go func() {
|
||||
@@ -148,7 +154,7 @@ func TestBrowserMCPRelaysToTheExtension(t *testing.T) {
|
||||
}
|
||||
json.NewDecoder(st.Body).Decode(&status)
|
||||
st.Body.Close()
|
||||
if !status.Connected || status.Extension != "0.1.0" || status.Browser != "Chrome/140" {
|
||||
if !status.Connected || status.Extension != browserext.Version() || status.Browser != "Chrome/140" {
|
||||
t.Fatalf("status: %+v", status)
|
||||
}
|
||||
}
|
||||
@@ -311,7 +317,7 @@ func TestBrowserMCPPicksAmongBrowsers(t *testing.T) {
|
||||
if got, _ := tabs("s1", map[string]any{}); !strings.Contains(got, "tabs of edge") || !strings.Contains(got, "b2's tabs (Edge 141); 2 browsers") {
|
||||
t.Fatalf("s1 before picking: %q", got)
|
||||
}
|
||||
if got, _ := tabs("s1", map[string]any{"action": "browsers"}); !strings.Contains(got, " b1 Chrome 141, extension 0.1.0") || !strings.Contains(got, "* b2 Edge 141, extension 0.1.0") {
|
||||
if got, _ := tabs("s1", map[string]any{"action": "browsers"}); !strings.Contains(got, " b1 Chrome 141, extension "+browserext.Version()) || !strings.Contains(got, "* b2 Edge 141, extension "+browserext.Version()) {
|
||||
t.Fatalf("browsers: %q", got)
|
||||
}
|
||||
if got, bad := tabs("s1", map[string]any{"action": "use", "browser": "Chrome"}); bad || !strings.Contains(got, "b1 (Chrome 141)") {
|
||||
|
||||
@@ -6541,6 +6541,9 @@ magpie.plugin("library", (ctx) => {
|
||||
function browserSetup() {
|
||||
const box = el("div", "mk-browser");
|
||||
const state = el("div", "mk-browser-state");
|
||||
// a connected extension older than magpie's: its folder has the new
|
||||
// one, but the browser runs the old until it is reloaded
|
||||
const update = el("p", "mk-browser-update");
|
||||
const steps = el("ol", "mk-browser-steps");
|
||||
let away = false;
|
||||
const go = button(t("Set up the extension…"), "action", async () => {
|
||||
@@ -6580,6 +6583,10 @@ magpie.plugin("library", (ctx) => {
|
||||
? t("Connected to your browser") + (b.extension ? " · " + b.extension : "")
|
||||
: away ? t("Not connected: download the extension and load it in your browser")
|
||||
: b.written ? t("Not connected: load the folder below in your browser, and keep that browser open") : t("Not set up: set up the extension in Chrome, Edge, Arc, Brave or another Chromium browser")));
|
||||
update.hidden = !(b.connected && b.outdated);
|
||||
update.textContent = update.hidden ? "" : away
|
||||
? t("Magpie Browser {v} is ready: download the extension again, unzip it over the old folder, and reload Magpie Browser on chrome://extensions (edge://extensions in Edge).", { v: b.version })
|
||||
: t("Magpie Browser {v} is ready: reload Magpie Browser on chrome://extensions (edge://extensions in Edge).", { v: b.version });
|
||||
go.textContent = away ? t("Download the extension") : b.written ? t("Show the extension folder") : t("Set up the extension…");
|
||||
if (away) {
|
||||
steps.replaceChildren(
|
||||
@@ -6620,7 +6627,8 @@ magpie.plugin("library", (ctx) => {
|
||||
folder.addEventListener("dragstart", (e) => e.preventDefault());
|
||||
steps.hidden = true;
|
||||
folder.hidden = true;
|
||||
box.append(state, steps, folder, go);
|
||||
update.hidden = true;
|
||||
box.append(state, update, steps, folder, go);
|
||||
const poll = async () => {
|
||||
if (!box.isConnected) return;
|
||||
try { draw(await api("library/browser")); } catch {}
|
||||
|
||||
@@ -165,6 +165,8 @@ magpie.strings({
|
||||
"Set up the extension…": "安装扩展…",
|
||||
"Show the extension folder": "显示扩展文件夹",
|
||||
"Connected to your browser": "已连接到你的浏览器",
|
||||
"Magpie Browser {v} is ready: reload Magpie Browser on chrome://extensions (edge://extensions in Edge).": "Magpie Browser {v} 已就绪:在 chrome://extensions(Edge 里是 edge://extensions)重新加载 Magpie Browser。",
|
||||
"Magpie Browser {v} is ready: download the extension again, unzip it over the old folder, and reload Magpie Browser on chrome://extensions (edge://extensions in Edge).": "Magpie Browser {v} 已就绪:重新下载扩展,解压覆盖旧文件夹,再在 chrome://extensions(Edge 里是 edge://extensions)重新加载 Magpie Browser。",
|
||||
"Connected to your browser. Which agents may use it? They act in your tabs, signed in as you are.": "已连接到你的浏览器。哪些 Agent 可以使用它?它们会在你的标签页里,以你的登录身份操作。",
|
||||
"Not connected: load the folder below in your browser, and keep that browser open": "未连接:在浏览器里加载下面的文件夹,并保持该浏览器打开",
|
||||
"Not set up: set up the extension in Chrome, Edge, Arc, Brave or another Chromium browser": "未安装:在 Chrome、Edge、Arc、Brave 或其他 Chromium 浏览器里安装扩展",
|
||||
@@ -973,6 +975,8 @@ magpie.strings({
|
||||
"Set up the extension…": "安裝擴充功能…",
|
||||
"Show the extension folder": "顯示擴充功能資料夾",
|
||||
"Connected to your browser": "已連線到你的瀏覽器",
|
||||
"Magpie Browser {v} is ready: reload Magpie Browser on chrome://extensions (edge://extensions in Edge).": "Magpie Browser {v} 已就緒:在 chrome://extensions(Edge 裡是 edge://extensions)重新載入 Magpie Browser。",
|
||||
"Magpie Browser {v} is ready: download the extension again, unzip it over the old folder, and reload Magpie Browser on chrome://extensions (edge://extensions in Edge).": "Magpie Browser {v} 已就緒:重新下載擴充功能,解壓縮覆蓋舊資料夾,再在 chrome://extensions(Edge 裡是 edge://extensions)重新載入 Magpie Browser。",
|
||||
"Connected to your browser. Which agents may use it? They act in your tabs, signed in as you are.": "已連線到你的瀏覽器。哪些 Agent 可以使用它?它們會在你的分頁裡,以你的登入身分操作。",
|
||||
"Not connected: load the folder below in your browser, and keep that browser open": "未連線:在瀏覽器裡載入下面的資料夾,並保持該瀏覽器開啟",
|
||||
"Not set up: set up the extension in Chrome, Edge, Arc, Brave or another Chromium browser": "未安裝:在 Chrome、Edge、Arc、Brave 或其他 Chromium 瀏覽器裡安裝擴充功能",
|
||||
@@ -1776,6 +1780,8 @@ magpie.strings({
|
||||
"Set up the extension…": "拡張機能を設定…",
|
||||
"Show the extension folder": "拡張機能のフォルダを表示",
|
||||
"Connected to your browser": "ブラウザに接続しました",
|
||||
"Magpie Browser {v} is ready: reload Magpie Browser on chrome://extensions (edge://extensions in Edge).": "Magpie Browser {v} を利用できます:chrome://extensions(Edge では edge://extensions)で Magpie Browser を再読み込みしてください。",
|
||||
"Magpie Browser {v} is ready: download the extension again, unzip it over the old folder, and reload Magpie Browser on chrome://extensions (edge://extensions in Edge).": "Magpie Browser {v} を利用できます:拡張機能をもう一度ダウンロードし、古いフォルダに上書きで展開してから、chrome://extensions(Edge では edge://extensions)で Magpie Browser を再読み込みしてください。",
|
||||
"Connected to your browser. Which agents may use it? They act in your tabs, signed in as you are.": "ブラウザに接続しました。どのエージェントに使わせますか?エージェントはあなたのタブで、あなたとしてサインインした状態で操作します。",
|
||||
"Not connected: load the folder below in your browser, and keep that browser open": "未接続:下のフォルダをブラウザで読み込み、そのブラウザを開いたままにしてください",
|
||||
"Not set up: set up the extension in Chrome, Edge, Arc, Brave or another Chromium browser": "未設定:Chrome、Edge、Arc、Brave などの Chromium ブラウザに拡張機能を設定してください",
|
||||
@@ -2582,6 +2588,8 @@ magpie.strings({
|
||||
"Set up the extension…": "Erweiterung einrichten…",
|
||||
"Show the extension folder": "Ordner der Erweiterung zeigen",
|
||||
"Connected to your browser": "Mit deinem Browser verbunden",
|
||||
"Magpie Browser {v} is ready: reload Magpie Browser on chrome://extensions (edge://extensions in Edge).": "Magpie Browser {v} ist bereit: Lade Magpie Browser auf chrome://extensions (edge://extensions in Edge) neu.",
|
||||
"Magpie Browser {v} is ready: download the extension again, unzip it over the old folder, and reload Magpie Browser on chrome://extensions (edge://extensions in Edge).": "Magpie Browser {v} ist bereit: Lade die Erweiterung erneut herunter, entpacke sie über den alten Ordner und lade Magpie Browser auf chrome://extensions (edge://extensions in Edge) neu.",
|
||||
"Connected to your browser. Which agents may use it? They act in your tabs, signed in as you are.": "Mit deinem Browser verbunden. Welche Agents dürfen ihn nutzen? Sie handeln in deinen Tabs, angemeldet wie du.",
|
||||
"Not connected: load the folder below in your browser, and keep that browser open": "Nicht verbunden: Lade den Ordner unten in deinem Browser und lass diesen Browser offen",
|
||||
"Not set up: set up the extension in Chrome, Edge, Arc, Brave or another Chromium browser": "Nicht eingerichtet: Richte die Erweiterung in Chrome, Edge, Arc, Brave oder einem anderen Chromium-Browser ein",
|
||||
|
||||
@@ -798,6 +798,8 @@ input.lib-setname:focus { border-color: var(--accent); box-shadow: 0 0 0 3px col
|
||||
.mk-sheet .mk-browser-state { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
|
||||
.mk-sheet .mk-browser-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
|
||||
.mk-sheet .mk-browser-dot.on { background: var(--green); }
|
||||
.mk-sheet .mk-browser-update { margin: 0; font-size: 12px; color: var(--fg-2); }
|
||||
.mk-sheet .mk-browser-update[hidden] { display: none; }
|
||||
.mk-sheet .mk-browser-steps { margin: 0; padding-left: 18px; font-size: 12px; color: var(--muted); display: grid; gap: 2px; }
|
||||
.mk-sheet .mk-browser-folder { display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: 10px; align-items: center; max-width: 100%; box-sizing: border-box; padding: 8px 12px; border: 1px dashed var(--line); border-radius: 8px; background: var(--card); cursor: grab; user-select: none; -webkit-user-select: none; touch-action: none; }
|
||||
.mk-sheet .mk-browser-folder[hidden] { display: none; }
|
||||
|
||||
@@ -39,6 +39,10 @@ type browserJSON struct {
|
||||
// the browser's reach; the extension is downloaded instead, with a
|
||||
// gateway key of its own (browserKey)
|
||||
Away bool `json:"away,omitempty"`
|
||||
// Outdated: the connected extension is older than Version. Its folder
|
||||
// has this magpie's, but the browser runs what it loaded until the
|
||||
// extension is reloaded, so the sheet says to reload it
|
||||
Outdated bool `json:"outdated,omitempty"`
|
||||
}
|
||||
|
||||
// browserAway is whether r's page is in a browser magpie's folders are out
|
||||
@@ -127,6 +131,7 @@ func browserState(ctx context.Context) browserJSON {
|
||||
}
|
||||
if resp.StatusCode == http.StatusOK && json.NewDecoder(resp.Body).Decode(&st) == nil {
|
||||
out.Connected, out.Extension, out.Browser = st.Connected, st.Extension, st.Browser
|
||||
out.Outdated = st.Connected && st.Extension != "" && browserext.Older(st.Extension, out.Version)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/browserext"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
)
|
||||
|
||||
// The sheet says to reload the extension when the connected one is older
|
||||
// than this magpie's (the browser runs what it loaded until then), and not
|
||||
// when it is as new, or when none is connected.
|
||||
func TestBrowserStateOutdated(t *testing.T) {
|
||||
sandboxHome(t)
|
||||
var st map[string]any
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != gateway.BrowserStatusPath {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
json.NewEncoder(w).Encode(st)
|
||||
}))
|
||||
t.Cleanup(srv.Close)
|
||||
t.Setenv("MAGPIE_ADDR", strings.TrimPrefix(srv.URL, "http://"))
|
||||
if gateway.URL() != srv.URL {
|
||||
t.Fatalf("the gateway is at %s, not %s", gateway.URL(), srv.URL)
|
||||
}
|
||||
v := browserext.Version()
|
||||
for _, c := range []struct {
|
||||
connected bool
|
||||
ext string
|
||||
want bool
|
||||
}{{true, "0.0.1", true}, {true, v, false}, {true, v + ".1", false}, {false, "0.0.1", false}, {true, "", false}} {
|
||||
st = map[string]any{"connected": c.connected, "extension": c.ext}
|
||||
if got := browserState(context.Background()); got.Outdated != c.want || got.Extension != c.ext && c.connected {
|
||||
t.Errorf("connected %v, extension %q: %+v", c.connected, c.ext, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,8 +24,8 @@ const DIR = `${HOME}/Magpie Browser Extension`;
|
||||
const ABOUT = "Use your own browser: your tabs, signed in to the sites you use. Open pages, click, type, upload, read and take screenshots, through the Magpie Browser extension.";
|
||||
|
||||
function fixture(lang) {
|
||||
const st = { connected: false, setups: 0, downloads: [] };
|
||||
const browser = () => ({ dir: DIR, written: false, version: "0.1.7", connected: st.connected, away: true, ...(st.connected ? { extension: "0.1.7", browser: "Chrome/141" } : {}) });
|
||||
const st = { connected: false, setups: 0, downloads: [], ext: "0.1.7" };
|
||||
const browser = () => ({ dir: DIR, written: false, version: "0.1.7", connected: st.connected, away: true, ...(st.connected ? { extension: st.ext, browser: "Chrome/141", ...(st.ext !== "0.1.7" ? { outdated: true } : {}) } : {}) });
|
||||
const route = async (route) => {
|
||||
const req = route.request(), url = new URL(req.url());
|
||||
const json = (data) => route.fulfill({ json: data });
|
||||
@@ -128,7 +128,17 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
w("Connected to your browser") + " · 0.1.7", { timeout: 10000 });
|
||||
assert.equal(await state.locator(".mk-browser-dot.on").count(), 1);
|
||||
assert.equal(await box.locator(".mk-browser-steps").isVisible(), false);
|
||||
assert.equal(await box.locator(".mk-browser-update").isVisible(), false);
|
||||
assert.equal(await wide(page), 0);
|
||||
|
||||
// an older one connected: downloaded again, over the old folder
|
||||
f.st.ext = "0.1.6";
|
||||
await page.waitForFunction((s) => document.querySelector("#modal .mk-browser-update:not([hidden])")?.textContent === s,
|
||||
w("Magpie Browser {v} is ready: download the extension again, unzip it over the old folder, and reload Magpie Browser on chrome://extensions (edge://extensions in Edge).", { v: "0.1.7" }), { timeout: 10000 });
|
||||
assert.equal((await go.textContent()).trim(), w("Download the extension"));
|
||||
assert.equal(await wide(page), 0);
|
||||
assert.equal(await sheet.evaluate((e) => e.scrollWidth - e.clientWidth), 0);
|
||||
shots.push([`${lang}-${width}-outdated`, await sheet.screenshot()]);
|
||||
assert.deepEqual(errors, []);
|
||||
await context.close();
|
||||
});
|
||||
|
||||
@@ -26,10 +26,10 @@ const DIR = `${HOME}/Magpie Browser Extension`;
|
||||
const ABOUT = "Use your own browser: your tabs, signed in to the sites you use. Open pages, click, type, upload, read and take screenshots, through the Magpie Browser extension.";
|
||||
|
||||
function fixture(lang, drag) {
|
||||
const st = { written: false, connected: false, setups: 0, drags: 0 };
|
||||
const st = { written: false, connected: false, setups: 0, drags: 0, ext: "0.1.0" };
|
||||
let onDrag;
|
||||
const dragged = new Promise((ok) => { onDrag = ok; });
|
||||
const browser = () => ({ dir: DIR, written: st.written, version: "0.1.0", connected: st.connected, ...(drag ? { drag: true } : {}), ...(st.connected ? { extension: "0.1.0", browser: "Chrome/141" } : {}) });
|
||||
const browser = () => ({ dir: DIR, written: st.written, version: "0.1.0", connected: st.connected, ...(drag ? { drag: true } : {}), ...(st.connected ? { extension: st.ext, browser: "Chrome/141", ...(st.ext !== "0.1.0" ? { outdated: true } : {}) } : {}) });
|
||||
const route = async (route) => {
|
||||
const req = route.request(), url = new URL(req.url());
|
||||
const json = (data) => route.fulfill({ json: data });
|
||||
@@ -165,7 +165,22 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
assert.equal(await box.locator(".mk-browser-steps").isVisible(), false);
|
||||
assert.equal(await box.locator(".mk-browser-folder").isVisible(), false);
|
||||
assert.equal(await wide(page), 0);
|
||||
assert.equal(await box.locator(".mk-browser-update").isVisible(), false);
|
||||
shots.push([`${lang}-${width}-${drag ? "drag" : "nodrag"}-connected`, await sheet.screenshot()]);
|
||||
|
||||
// an older extension connected: the browser runs it until it is
|
||||
// reloaded, so the sheet says to reload it, and stops once it is
|
||||
f.st.ext = "0.0.9";
|
||||
const update = box.locator(".mk-browser-update");
|
||||
await page.waitForFunction((s) => document.querySelector("#modal .mk-browser-update:not([hidden])")?.textContent === s,
|
||||
w("Magpie Browser {v} is ready: reload Magpie Browser on chrome://extensions (edge://extensions in Edge).", { v: "0.1.0" }), { timeout: 10000 });
|
||||
assert.equal(await state.textContent(), w("Connected to your browser") + " · 0.0.9");
|
||||
assert.equal(await update.isVisible(), true);
|
||||
assert.equal(await wide(page), 0);
|
||||
assert.equal(await sheet.evaluate((e) => e.scrollWidth - e.clientWidth), 0);
|
||||
shots.push([`${lang}-${width}-${drag ? "drag" : "nodrag"}-outdated`, await sheet.screenshot()]);
|
||||
f.st.ext = "0.1.0";
|
||||
await page.waitForFunction(() => document.querySelector("#modal .mk-browser-update")?.hidden === true, null, { timeout: 10000 });
|
||||
assert.deepEqual(errors, []);
|
||||
await context.close();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user