Skip to content

[Bug] Chrome extensions not loading - content scripts not injected #640

@jtstothard

Description

@jtstothard

Description

Chrome extensions are not working with agent-browser. Content scripts are not being injected into pages, even though the extension appears to load (background pages are visible in CDP).

Interestingly, using Playwright directly does work when channel: 'chromium' is specified, suggesting the issue is specific to how agent-browser configures Playwright.

Reproduction

# 1. Create a minimal test extension
mkdir -p /tmp/test-extension
cat > /tmp/test-extension/manifest.json <<'EOF'
{
  "manifest_version": 3,
  "name": "Test Extension",
  "version": "1.0",
  "content_scripts": [
    {
      "matches": ["<all_urls>"],
      "js": ["content.js"],
      "run_at": "document_idle"
    }
  ]
}
EOF

cat > /tmp/test-extension/content.js <<'EOF'
console.log('[TEST EXTENSION] Injected!');
window.TEST_EXTENSION_LOADED = true;
document.body.style.border = "5px solid red";
EOF

# 2. Launch with extension
agent-browser close
agent-browser --headed --extension /tmp/test-extension open https://example.com

# 3. Check if content script ran
agent-browser eval 'window.TEST_EXTENSION_LOADED'  # Returns undefined, should be true
agent-browser console  # No "[TEST EXTENSION] Injected!" message

Expected Behavior

Extension content scripts should be injected and execute. When using Playwright directly with the same configuration, it works:

import { chromium } from 'playwright';
const context = await chromium.launchPersistentContext(userDataDir, {
  channel: 'chromium',
  args: [`--load-extension=${extPath}`, `--disable-extensions-except=${extPath}`]
});
// Result: content scripts ARE injected ✅

Workaround

Use Playwright directly instead of agent-browser. The following configuration works:

import { chromium } from 'playwright-core';

const extensionPath = '/path/to/extension';
const context = await chromium.launchPersistentContext(userDataDir, {
  headless: false,
  channel: 'chromium',  // This is required!
  args: [
    `--disable-extensions-except=${extensionPath}`,
    `--load-extension=${extensionPath}`
  ]
});

Investigation

  1. Fix attempted: Added channel: 'chromium' to dist/browser.js line 1147 in the launchPersistentContext call (where hasExtensions is true)
  2. Result: Fix works with Playwright directly, but NOT through agent-browser
  3. Both Playwright and Native modes tested - neither works
  4. Manual Chrome launch with --load-extension also doesn't inject content scripts on macOS Chrome 147

This suggests the issue may be deeper than just the channel parameter - possibly related to:

  • How agent-browser's daemon caches code
  • Chrome 147 + macOS specific behavior
  • User data directory state

Environment

  • agent-browser: 0.16.3
  • Playwright: 1.58.2
  • OS: macOS (Darwin 25.2.0, arm64)
  • Chrome: 147.0.7632.160 (system Chrome)

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions