Browser Swarm Docs
  • ๐Ÿš€Welcome
    • What is Browser Swarm?
  • Understanding Headless Browsers
  • Quickstart Guide
  • Framework Compatibility
  • ๐ŸŒŸ Core Concepts
    • Starting a Browser Task
  • Interacting with Browser Tasks
  • Task Lifecycle Management
  • โš™๏ธAdvanced Features
    • Stealth Automation
  • Proxy Integration
  • Real-Time Monitoring
  • Responsive Viewports
  • Session Debugging & Replay
  • File Handling (Downloads & Uploads)
  • Capturing Screenshots & PDFs
  • Persistent Contexts
  • Extension Support
  • Session Tagging & Metadata
  • ๐ŸŽฏPractical Examples
    • Automating Form Interactions
  • Efficient Data Scraping
  • Automated Web Testing
  • Cost Optimization Strategies
  • Handling Extended Tasks
  • Selecting Execution Regions
  • Monitoring Resource Usage
  • Leveraging Task Metadata
  • Pricing and Subscription
  • Account and Team Management
  • Managing Limits and Concurrency
  • Authentication Automation
  • Security Best Practices
  • ๐Ÿ”ŒEcosystem Integrations
    • Integration Overview
  • ๐Ÿ’ปDeveloper Resources
    • APIs and SDKs Overview
  • Node.js Integration
  • Python Integration
  • Browser Task API
  • Project Management API
  • Context Management API
  • Browser Extensions API
  • ๐Ÿ™‹โ€โ™‚๏ธSupport & Resources
    • Getting Help
  • Dashboard Overview
  • FAQs & Troubleshooting
Powered by GitBook
On this page
  • ๐Ÿš€ Why Use Extensions?
  • ๐Ÿ“ฆ Preparing Your Extension
  • ๐Ÿ“ค Uploading Your Extension
  • ๐Ÿงช Using Extensions in Sessions
  • ๐Ÿ’ก Best Practices

Extension Support

Browser Swarm empowers you to enhance your browser automation sessions by integrating custom Chrome extensions. This feature is invaluable for tasks requiring specialized browser behavior, such as modifying HTTP headers, injecting scripts, or automating interactions with third-party services.


๐Ÿš€ Why Use Extensions?

Integrating extensions into your browser sessions allows you to:

  • Modify Page Behavior: Alter or enhance the functionality of web pages during automation.

  • Automate Complex Workflows: Interact with third-party tools or services seamlessly.

  • Enhance Testing Capabilities: Simulate user interactions more effectively for comprehensive testing.

  • Implement Custom Security Measures: Enforce specific security protocols or monitoring within sessions.

By leveraging extensions, you can tailor browser sessions to meet specific requirements, ensuring more robust and flexible automation.


๐Ÿ“ฆ Preparing Your Extension

To integrate an extension with Browser Swarm, ensure it adheres to the following:

  • Format: The extension should be packaged as a .zip file.

  • Structure: The root of the .zip must contain a valid manifest.json file.

  • Size Limit: The total size should not exceed 4.5 MB.

Here's a basic example of a manifest.json file:

{
  "manifest_version": 3,
  "name": "My Custom Extension",
  "version": "1.0",
  "description": "A simple extension example",
  "content_scripts": [
    {
      "matches": ["https://example.com/*"],
      "js": ["content-script.js"]
    }
  ]
}

Ensure that all referenced files, like content-script.js, are included in the .zip package.


๐Ÿ“ค Uploading Your Extension

Once your extension is prepared, upload it to Browser Swarm using our SDKs.

Example

import { BrowserSwarm } from 'browser-swarm-sdk';
import fs from 'fs';

const bs = new BrowserSwarm({ apiKey: process.env.BROWSER_SWARM_API_KEY });

(async () => {
  const fileBuffer = fs.readFileSync('extension.zip');
  const extension = await bs.extensions.create({ file: fileBuffer });
  console.log(`Extension uploaded with ID: ${extension.id}`);
})();
from browser_swarm import BrowserSwarm
import os

bs = BrowserSwarm(api_key=os.environ["BROWSER_SWARM_API_KEY"])

with open("extension.zip", "rb") as f:
    extension = bs.extensions.create(f)

print(f"Extension uploaded with ID: {extension.id}")

Upon successful upload, you'll receive an extension.id which you'll use to associate the extension with your browser sessions.


๐Ÿงช Using Extensions in Sessions

To utilize your uploaded extension in a browser session, specify the extension_id when creating the session.

Example

const session = await bs.sessions.create({
  projectId: process.env.BROWSER_SWARM_PROJECT_ID,
  extensionId: 'your-extension-id'
});
session = bs.sessions.create(
    project_id=os.environ["BROWSER_SWARM_PROJECT_ID"],
    extension_id="your-extension-id"
)

This will launch a browser session with your custom extension loaded and active.


๐Ÿ’ก Best Practices

  • Test Locally: Before uploading, test your extension in a local Chrome browser to ensure it functions as intended.

  • Minimize Size: Keep the extension as lightweight as possible to stay within the size limit and ensure faster loading times.

  • Handle Errors Gracefully: Implement error handling within your extension to prevent it from crashing the browser session.

  • Maintain Security: Avoid including sensitive information within the extension code or assets

By following these practices, you can ensure that your extensions enhance your automation tasks effectively and securely.


Integrating custom extensions with Browser Swarm opens up a realm of possibilities for browser automation, allowing for tailored solutions to complex challenges.

PreviousPersistent ContextsNextSession Tagging & Metadata

Last updated 1 month ago