Skip to content

Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠

fix: export SafeSocial settings

Emre Sokullubc6f5fd7c952
diff --git a/src/chrome/src/config-transfer.js b/src/chrome/src/config-transfer.js
index d0c90d260..1aac9a21b 100644
--- a/src/chrome/src/config-transfer.js
+++ b/src/chrome/src/config-transfer.js
@@ -11,6 +11,7 @@ import {
USER_MEMORY_STORAGE_KEY,
} from './agent/user-memory.js';
import { AUTO_GROUP_TABS_KEY } from './tab-group-preference.js';
+import { normalizeSettings as normalizeSafeSocialSettings, SETTINGS_KEY as SAFE_SOCIAL_SETTINGS_KEY } from './safesocial/config.js';
import { normalizeUiScale, UI_SCALE_STORAGE_KEY } from './ui/ui-scale.js';
export const CONFIG_SCHEMA = 'webbrain-config/1';
@@ -85,6 +86,7 @@ export const DEFAULT_CONFIG_SETTINGS = Object.freeze({
systemOneWatchThreshold: 0.7,
systemOneCompletionThreshold: 0.7,
typesafeApiKey: '',
+ [SAFE_SOCIAL_SETTINGS_KEY]: normalizeSafeSocialSettings(),
});
export const CONFIG_STORAGE_KEYS = Object.freeze(Object.keys(DEFAULT_CONFIG_SETTINGS));
@@ -190,7 +192,7 @@ function validSettingValue(key, value) {
if (STRING_KEYS.has(key)) return typeof value === 'string';
if (ARRAY_KEYS.has(key)) return Array.isArray(value);
if (NULLABLE_OBJECT_KEYS.has(key)) return value === null || isPlainObject(value);
- if (key === 'providers' || key === USER_MEMORY_STORAGE_KEY) return isPlainObject(value);
+ if (key === 'providers' || key === USER_MEMORY_STORAGE_KEY || key === SAFE_SOCIAL_SETTINGS_KEY) return isPlainObject(value);
return true;
}
@@ -208,6 +210,14 @@ function normalizeSettings(source, { strict = false } = {}) {
settings[key] = normalizeUiScale(value);
continue;
}
+ if (key === SAFE_SOCIAL_SETTINGS_KEY) {
+ if (!isPlainObject(value)) {
+ if (strict) throw new Error(`Invalid value for configuration setting "${key}".`);
+ continue;
+ }
+ settings[key] = normalizeSafeSocialSettings(value);
+ continue;
+ }
if (!validSettingValue(key, value)) {
if (strict) throw new Error(`Invalid value for configuration setting "${key}".`);
continue;
@@ -287,6 +297,8 @@ export function parseConfigPatchImport(json) {
}
settings[key] = key === UI_SCALE_STORAGE_KEY
? normalizeUiScale(value)
+ : key === SAFE_SOCIAL_SETTINGS_KEY
+ ? normalizeSafeSocialSettings(value)
: key === 'providers'
? sanitizeProviders(value, { strict: true })
: clone(value);
diff --git a/src/firefox/src/config-transfer.js b/src/firefox/src/config-transfer.js
index d0c90d260..1aac9a21b 100644
--- a/src/firefox/src/config-transfer.js
+++ b/src/firefox/src/config-transfer.js
@@ -11,6 +11,7 @@ import {
USER_MEMORY_STORAGE_KEY,
} from './agent/user-memory.js';
import { AUTO_GROUP_TABS_KEY } from './tab-group-preference.js';
+import { normalizeSettings as normalizeSafeSocialSettings, SETTINGS_KEY as SAFE_SOCIAL_SETTINGS_KEY } from './safesocial/config.js';
import { normalizeUiScale, UI_SCALE_STORAGE_KEY } from './ui/ui-scale.js';
export const CONFIG_SCHEMA = 'webbrain-config/1';
@@ -85,6 +86,7 @@ export const DEFAULT_CONFIG_SETTINGS = Object.freeze({
systemOneWatchThreshold: 0.7,
systemOneCompletionThreshold: 0.7,
typesafeApiKey: '',
+ [SAFE_SOCIAL_SETTINGS_KEY]: normalizeSafeSocialSettings(),
});
export const CONFIG_STORAGE_KEYS = Object.freeze(Object.keys(DEFAULT_CONFIG_SETTINGS));
@@ -190,7 +192,7 @@ function validSettingValue(key, value) {
if (STRING_KEYS.has(key)) return typeof value === 'string';
if (ARRAY_KEYS.has(key)) return Array.isArray(value);
if (NULLABLE_OBJECT_KEYS.has(key)) return value === null || isPlainObject(value);
- if (key === 'providers' || key === USER_MEMORY_STORAGE_KEY) return isPlainObject(value);
+ if (key === 'providers' || key === USER_MEMORY_STORAGE_KEY || key === SAFE_SOCIAL_SETTINGS_KEY) return isPlainObject(value);
return true;
}
@@ -208,6 +210,14 @@ function normalizeSettings(source, { strict = false } = {}) {
settings[key] = normalizeUiScale(value);
continue;
}
+ if (key === SAFE_SOCIAL_SETTINGS_KEY) {
+ if (!isPlainObject(value)) {
+ if (strict) throw new Error(`Invalid value for configuration setting "${key}".`);
+ continue;
+ }
+ settings[key] = normalizeSafeSocialSettings(value);
+ continue;
+ }
if (!validSettingValue(key, value)) {
if (strict) throw new Error(`Invalid value for configuration setting "${key}".`);
continue;
@@ -287,6 +297,8 @@ export function parseConfigPatchImport(json) {
}
settings[key] = key === UI_SCALE_STORAGE_KEY
? normalizeUiScale(value)
+ : key === SAFE_SOCIAL_SETTINGS_KEY
+ ? normalizeSafeSocialSettings(value)
: key === 'providers'
? sanitizeProviders(value, { strict: true })
: clone(value);
diff --git a/test/safesocial.mjs b/test/safesocial.mjs
index 2e3aab7b7..b4adcf88b 100644
--- a/test/safesocial.mjs
+++ b/test/safesocial.mjs
@@ -4,6 +4,7 @@ import { readFile } from 'node:fs/promises';
for (const build of ['chrome', 'firefox']) {
const config = await import(`../src/${build}/src/safesocial/config.js`);
+ const configTransfer = await import(`../src/${build}/src/config-transfer.js`);
const { installSafeSocialBackground } = await import(`../src/${build}/src/safesocial/background.js`);
const { createSafeSocialHost } = await import(`../src/${build}/src/safesocial/host.js`);
test(`${build}: opt-in defaults, score selection, strict URL boundaries and training preprocessing`, () => {
@@ -25,6 +26,33 @@ for (const build of ['chrome', 'firefox']) {
const pixels = config.normalizedPixels([255, 0, 128, 255], { image_size: 1, mean: [0, .5, 0], std: [1, .5, 1] });
assert.equal(pixels[0], 1); assert.equal(pixels[1], -1); assert.ok(Math.abs(pixels[2] - 128 / 255) < 1e-7);
});
+ test(`${build}: configuration transfer preserves normalized SafeSocial settings`, () => {
+ const exported = configTransfer.createConfigExport({
+ [config.SETTINGS_KEY]: {
+ enabled: true,
+ action: 'hide',
+ threshold: 2,
+ labels: { social_fomo: true, luxury_status: false },
+ },
+ });
+ assert.deepEqual(exported.settings[config.SETTINGS_KEY], config.normalizeSettings({
+ enabled: true,
+ action: 'hide',
+ threshold: 2,
+ labels: { social_fomo: true, luxury_status: false },
+ }));
+ const restored = configTransfer.parseConfigImport(JSON.stringify(exported));
+ assert.deepEqual(restored.settings[config.SETTINGS_KEY], exported.settings[config.SETTINGS_KEY]);
+ const patch = configTransfer.parseConfigPatchImport(JSON.stringify({
+ ...exported,
+ settings: { [config.SETTINGS_KEY]: { enabled: true, threshold: 0 } },
+ }));
+ assert.deepEqual(patch.settings[config.SETTINGS_KEY], config.normalizeSettings({ enabled: true, threshold: 0 }));
+ assert.throws(() => configTransfer.parseConfigImport(JSON.stringify({
+ ...exported,
+ settings: { [config.SETTINGS_KEY]: true },
+ })), /safeSocialSettings/);
+ });
function harness() {
let settings = config.normalizeSettings();
let onChange;