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}`);
})();

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'
});

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.

Last updated