Skip to content

Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.

fix(computer): reopen the file chooser after enabling extension file access

jeffrey5fefe5ed417a
diff --git a/apps/computer/local-daemon/README.md b/apps/computer/local-daemon/README.md
index 04d071ec..409b8e63 100644
--- a/apps/computer/local-daemon/README.md
+++ b/apps/computer/local-daemon/README.md
@@ -708,7 +708,9 @@ one client when the next connects, so its whole profile is one seat. Chrome lets
set a file input only when the user turns on Allow access to file URLs for it,
which is off by default. When the profile's preferences show it off, the Daemon
fails `browser_file_upload` with `BROWSER_FILE_ACCESS_DISABLED` before Chrome
-sees it, and the Agent asks the user to turn it on; the file chooser stays open. Release
+sees it. The Agent asks the user to turn it on, then opens the file chooser
+again: Chrome reloads the extension on the change, which closes the chooser,
+and saves the setting a few seconds later. Release
bundles patch Playwright to keep focus emulation on its CDP connections, this
Chrome and the Agent Chrome alike. Without it a background tab is hidden: it
stops rendering, clicks wait for it, and mouse and key events are lost. One task or Live call holds a seat at a time, so tasks of
diff --git a/apps/computer/local-daemon/internal/linger/localtools/browser.go b/apps/computer/local-daemon/internal/linger/localtools/browser.go
index 1d8d77ef..7a0b3b70 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/browser.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/browser.go
@@ -157,7 +157,7 @@ func (op *operation) nativeBrowserCall(ctx context.Context, name string, args js
// which later tasks of the same Agent reuse.
// A rejected token fails the call: it never falls back to the Agent profile.
func (op *operation) userChromeCall(ctx context.Context, chrome *browserConnection, name string, args json.RawMessage, confirmed *bool) (json.RawMessage, error) {
- if name == "browser_file_upload" && uploadsFiles(args) && extensionFileAccessOff(op.manager.env, chrome.Profile) {
+ if data := chromeUserDataDirectory(op.manager.env); name == "browser_file_upload" && uploadsFiles(args) && data != "" && extensionFileAccessOff(filepath.Join(data, chrome.Profile)) {
*confirmed = true
return nil, errUserChromeFileAccess
}
@@ -193,7 +193,7 @@ func (op *operation) userChromeCall(ctx context.Context, chrome *browserConnecti
return result, err
}
-var errUserChromeFileAccess = errors.New("BROWSER_FILE_ACCESS_DISABLED: the user's Chrome does not let the Playwright Extension read local files, so no file was attached. Ask the user to open chrome://extensions/?id=" + playwrightExtensionID + " and turn on Allow access to file URLs, then call browser_file_upload again; the file chooser is still open")
+var errUserChromeFileAccess = errors.New("BROWSER_FILE_ACCESS_DISABLED: the user's Chrome does not let the Playwright Extension read local files, so no file was attached. Ask the user to open chrome://extensions/?id=" + playwrightExtensionID + " and turn on Allow access to file URLs. Chrome then reloads the extension, which closes the file chooser, and saves the setting a few seconds later. After the user confirms, wait a few seconds, click the upload control again, and call browser_file_upload")
// uploadsFiles reports whether browser_file_upload arguments name files; a
// call without paths only cancels the file chooser.
diff --git a/apps/computer/local-daemon/internal/linger/localtools/user_chrome.go b/apps/computer/local-daemon/internal/linger/localtools/user_chrome.go
index 4527dffc..ed123671 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/user_chrome.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/user_chrome.go
@@ -143,19 +143,16 @@ func versionAtLeast(version string, minimum [3]int) bool {
return true
}
-// extensionFileAccessOff reports whether the profile's preferences show the
-// Playwright Extension without file access. Chrome rejects the extension's
-// DOM.setFileInputFiles without it, and only the user can turn it on. Chrome
-// keeps the switch, off by default, in Secure Preferences or Preferences.
-// Unreadable preferences report false so that Chrome decides.
-func extensionFileAccessOff(env []string, profile string) bool {
- data := chromeUserDataDirectory(env)
- if data == "" {
- return false
- }
+// extensionFileAccessOff reports whether the preferences in the Chrome
+// profile directory show the Playwright Extension without file access. Chrome
+// rejects the extension's DOM.setFileInputFiles without it, and only the user
+// can turn it on. Chrome keeps the switch, off by default, in Secure
+// Preferences or Preferences. Unreadable preferences report false so that
+// Chrome decides.
+func extensionFileAccessOff(profileDirectory string) bool {
read := false
for _, name := range []string{"Secure Preferences", "Preferences"} {
- encoded, err := os.ReadFile(filepath.Join(data, profile, name))
+ encoded, err := os.ReadFile(filepath.Join(profileDirectory, name))
if err != nil {
continue
}
diff --git a/apps/computer/local-daemon/internal/linger/localtools/user_chrome_test.go b/apps/computer/local-daemon/internal/linger/localtools/user_chrome_test.go
index f31a7447..9f0e3676 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/user_chrome_test.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/user_chrome_test.go
@@ -811,19 +811,11 @@ func TestLiveCallStopsWaitingWithItsCaller(t *testing.T) {
}
}
-func TestFileUploadReportsExtensionWithoutFileAccess(t *testing.T) {
- if runtime.GOOS != "darwin" && runtime.GOOS != "windows" {
- t.Skip("the everyday Chrome is connected on macOS and Windows")
- }
- writePrefs := func(env []string, name, body string) {
- t.Helper()
- if err := os.WriteFile(filepath.Join(chromeUserDataDirectory(env), "Default", name), []byte(body), 0o600); err != nil {
- t.Fatal(err)
- }
- }
- setting := func(value string) string {
- return `{"extensions":{"settings":{"` + playwrightExtensionID + `":{"location":1` + value + `}}}}`
- }
+func fileAccessPrefs(value string) string {
+ return `{"extensions":{"settings":{"` + playwrightExtensionID + `":{"location":1` + value + `}}}}`
+}
+
+func TestExtensionFileAccessPreference(t *testing.T) {
for _, test := range []struct {
name string
prefs map[string]string
@@ -831,23 +823,36 @@ func TestFileUploadReportsExtensionWithoutFileAccess(t *testing.T) {
}{
{"no preferences", nil, false},
{"unreadable preferences", map[string]string{"Secure Preferences": "{"}, false},
- {"default off", map[string]string{"Secure Preferences": setting("")}, true},
- {"turned off", map[string]string{"Secure Preferences": setting(`,"newAllowFileAccess":false`)}, true},
- {"turned on", map[string]string{"Secure Preferences": setting(`,"newAllowFileAccess":true`)}, false},
- {"turned on in Preferences", map[string]string{"Secure Preferences": setting(""), "Preferences": setting(`,"newAllowFileAccess":true`)}, false},
+ {"default off", map[string]string{"Secure Preferences": fileAccessPrefs("")}, true},
+ {"turned off", map[string]string{"Secure Preferences": fileAccessPrefs(`,"newAllowFileAccess":false`)}, true},
+ {"turned on", map[string]string{"Secure Preferences": fileAccessPrefs(`,"newAllowFileAccess":true`)}, false},
+ {"turned on in Preferences", map[string]string{"Secure Preferences": fileAccessPrefs(""), "Preferences": fileAccessPrefs(`,"newAllowFileAccess":true`)}, false},
} {
- env := chromeHome(t, "0.6.0_0")
+ profile := t.TempDir()
for name, body := range test.prefs {
- writePrefs(env, name, body)
+ if err := os.WriteFile(filepath.Join(profile, name), []byte(body), 0o600); err != nil {
+ t.Fatal(err)
+ }
}
- if got := extensionFileAccessOff(env, "Default"); got != test.off {
+ if got := extensionFileAccessOff(profile); got != test.off {
t.Errorf("%s: file access off = %v, want %v", test.name, got, test.off)
}
}
+ if uploadsFiles(json.RawMessage(`{}`)) || uploadsFiles(json.RawMessage(`{"paths":[]}`)) || !uploadsFiles(json.RawMessage(`{"paths":["/tmp/a.txt"]}`)) {
+ t.Fatal("only a call with paths counts as an upload; one without cancels the file chooser")
+ }
+}
+func TestFileUploadReportsExtensionWithoutFileAccess(t *testing.T) {
+ if runtime.GOOS != "darwin" && runtime.GOOS != "windows" {
+ t.Skip("the everyday Chrome is connected on macOS and Windows")
+ }
m := newConnectionManager(t)
m.env = chromeHome(t, "0.6.0_0")
- writePrefs(m.env, "Secure Preferences", setting(""))
+ prefs := filepath.Join(chromeUserDataDirectory(m.env), "Default", "Secure Preferences")
+ if err := os.WriteFile(prefs, []byte(fileAccessPrefs("")), 0o600); err != nil {
+ t.Fatal(err)
+ }
op := &operation{manager: m, label: "linger-test", userChrome: &browserConnection{Profile: "Default"}}
_, err := op.nativeBrowserCall(t.Context(), "browser_file_upload", json.RawMessage(`{"paths":["/tmp/report.txt"]}`))
if !errors.Is(err, errUserChromeFileAccess) {
@@ -856,7 +861,4 @@ func TestFileUploadReportsExtensionWithoutFileAccess(t *testing.T) {
if op.browser != nil {
t.Fatal("the refused upload started a Playwright session")
}
- if uploadsFiles(json.RawMessage(`{}`)) || uploadsFiles(json.RawMessage(`{"paths":[]}`)) {
- t.Fatal("cancelling the file chooser was treated as an upload")
- }
}