Skip to content

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

agent: treat WebBrain's own new tab page as a browser new tab

Claude706d753ef3e3
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 6d5e63912..9f76be089 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -703,7 +703,15 @@ function normalizeCaptchaGateState(gate) {
function isBrowserNewTabUrl(url) {
const value = String(url || '').toLowerCase();
- return BROWSER_NEW_TAB_URL_PREFIXES.some(prefix => value.startsWith(prefix));
+ if (BROWSER_NEW_TAB_URL_PREFIXES.some(prefix => value.startsWith(prefix))) return true;
+ // With chrome_url_overrides.newtab on, a fresh tab reports WebBrain's own new tab page.
+ try {
+ const own = new URL(chrome.runtime.getURL('newtab/index.html'));
+ const candidate = new URL(String(url || ''));
+ return candidate.protocol === own.protocol && candidate.host === own.host && candidate.pathname === own.pathname;
+ } catch {
+ return false;
+ }
}
// Only read a 3-digit number as a status code where it actually reads like
diff --git a/src/chrome/src/agent/bot-memory.js b/src/chrome/src/agent/bot-memory.js
index d0404c8dc..dbf01425a 100644
--- a/src/chrome/src/agent/bot-memory.js
+++ b/src/chrome/src/agent/bot-memory.js
@@ -1,5 +1,19 @@
/** Run-scoped, app-owned bot memory. Never persist the callback credential. */
import { isCredentialField } from './credential-fields.js';
+
+// WebBrain's own new tab page (chrome_url_overrides.newtab) is the browser's new tab
+// once the override is on, so it counts as a blank document here. Content scripts
+// do not run on it either.
+function isOwnNewTabPage(url) {
+ try {
+ const api = globalThis.browser?.runtime?.getURL ? globalThis.browser : globalThis.chrome;
+ const own = new URL(api.runtime.getURL('newtab/index.html'));
+ const candidate = new URL(url);
+ return candidate.protocol === own.protocol && candidate.host === own.host && candidate.pathname === own.pathname;
+ } catch {
+ return false;
+ }
+}
export const BOT_MEMORY_SCOPE_HEADER = '[Managed bot memory scope - profile memory and unscoped side conversations are unavailable.]';
const READ_TOOLS = new Set([
'calculate',
@@ -422,7 +436,8 @@ export class BotMemorySession {
const current = typeof tab?.url === 'string' ? tab.url : '';
if (tab?.url && tab?.pendingUrl && tab.pendingUrl !== tab.url) return false;
return ['about:blank', 'about:newtab', 'about:home', 'chrome://newtab/',
- 'chrome://new-tab-page/', 'edge://newtab/', 'chrome-search://local-ntp/local-ntp.html'].includes(current);
+ 'chrome://new-tab-page/', 'edge://newtab/', 'chrome-search://local-ntp/local-ntp.html'].includes(current)
+ || isOwnNewTabPage(current);
}
async prepare(tabId, name, args, { signal = null, consequentialSubmit = false, detectedSubmit = false } = {}) {
if (this.pending.size && (name === 'done_json' || (name === 'done' && !['partial', 'failed'].includes(args?.outcome)))) {
diff --git a/src/firefox/src/agent/bot-memory.js b/src/firefox/src/agent/bot-memory.js
index d0404c8dc..dbf01425a 100644
--- a/src/firefox/src/agent/bot-memory.js
+++ b/src/firefox/src/agent/bot-memory.js
@@ -1,5 +1,19 @@
/** Run-scoped, app-owned bot memory. Never persist the callback credential. */
import { isCredentialField } from './credential-fields.js';
+
+// WebBrain's own new tab page (chrome_url_overrides.newtab) is the browser's new tab
+// once the override is on, so it counts as a blank document here. Content scripts
+// do not run on it either.
+function isOwnNewTabPage(url) {
+ try {
+ const api = globalThis.browser?.runtime?.getURL ? globalThis.browser : globalThis.chrome;
+ const own = new URL(api.runtime.getURL('newtab/index.html'));
+ const candidate = new URL(url);
+ return candidate.protocol === own.protocol && candidate.host === own.host && candidate.pathname === own.pathname;
+ } catch {
+ return false;
+ }
+}
export const BOT_MEMORY_SCOPE_HEADER = '[Managed bot memory scope - profile memory and unscoped side conversations are unavailable.]';
const READ_TOOLS = new Set([
'calculate',
@@ -422,7 +436,8 @@ export class BotMemorySession {
const current = typeof tab?.url === 'string' ? tab.url : '';
if (tab?.url && tab?.pendingUrl && tab.pendingUrl !== tab.url) return false;
return ['about:blank', 'about:newtab', 'about:home', 'chrome://newtab/',
- 'chrome://new-tab-page/', 'edge://newtab/', 'chrome-search://local-ntp/local-ntp.html'].includes(current);
+ 'chrome://new-tab-page/', 'edge://newtab/', 'chrome-search://local-ntp/local-ntp.html'].includes(current)
+ || isOwnNewTabPage(current);
}
async prepare(tabId, name, args, { signal = null, consequentialSubmit = false, detectedSubmit = false } = {}) {
if (this.pending.size && (name === 'done_json' || (name === 'done' && !['partial', 'failed'].includes(args?.outcome)))) {
diff --git a/test/newtab.mjs b/test/newtab.mjs
index 2851b5634..2328d8ce2 100644
--- a/test/newtab.mjs
+++ b/test/newtab.mjs
@@ -800,3 +800,39 @@ test('the background settings header has a Hide/Show toggle', () => {
const src = readFileSync(nt('features/background/options/BackgroundOptions.jsx'), 'utf8');
assert.match(src, /setting="background"[\s\S]{0,120}visibilityToggle=\{true\}/);
});
+
+for (const browserName of ['chrome', 'firefox']) {
+ test(`${browserName}: Act can bootstrap navigation away from WebBrain's own new tab page`, async () => {
+ const { BotMemorySession } = await import(
+ pathToFileURL(path.join(root, 'src', browserName, 'src/agent/bot-memory.js')).href
+ );
+ const base = browserName === 'chrome' ? 'chrome-extension://abc123/' : 'moz-extension://uuid-1/';
+ const api = { runtime: { getURL: (p) => base + p } };
+ const prev = { chrome: globalThis.chrome, browser: globalThis.browser };
+ globalThis.chrome = api;
+ globalThis.browser = api;
+ try {
+ const check = (url) => {
+ const s = Object.create(BotMemorySession.prototype);
+ s.getTab = async () => ({ url });
+ return s.canBootstrapNavigation(1, 'navigate', { url: 'https://example.com/' });
+ };
+ assert.equal(await check(`${base}newtab/index.html`), true);
+ assert.equal(await check(`${base}newtab/index.html?x=1#y`), true);
+ assert.equal(await check(`${base}src/ui/history.html`), false); // other extension pages: no
+ assert.equal(await check('chrome-extension://evil/newtab/index.html'), browserName === 'chrome' ? false : false);
+ assert.equal(await check('https://example.com/newtab/index.html'), false);
+ } finally {
+ globalThis.chrome = prev.chrome;
+ globalThis.browser = prev.browser;
+ if (prev.chrome === undefined) delete globalThis.chrome;
+ if (prev.browser === undefined) delete globalThis.browser;
+ }
+ });
+}
+
+test('chrome agent treats the extension new tab page as a browser new tab', () => {
+ const src = readFileSync(path.join(root, 'src/chrome/src/agent/agent.js'), 'utf8');
+ const fn = src.slice(src.indexOf('function isBrowserNewTabUrl'), src.indexOf('function isBrowserNewTabUrl') + 700);
+ assert.match(fn, /runtime\.getURL\('newtab\/index\.html'\)/);
+});