Skip to content

Class: ExtensionsService ​

Overview ​

The Extension module provides capabilities for working with browser extensions and extending the functionality of the AGB platform.

Provides methods to manage user browser extensions. This service integrates with the existing context functionality for file operations.

Usage (Simplified - Auto-detection):

typescript
// Service automatically detects if context exists and creates if needed
const extensionsService = new ExtensionsService(agb, "browser_extensions");

// Or use with empty contextId to auto-generate context name
const extensionsService = new ExtensionsService(agb);  // Uses default generated name

// Use the service immediately - initialization happens automatically
const extension = await extensionsService.create("/path/to/plugin.zip");

Integration with ExtensionOption (Simplified):

typescript
// Create extensions and configure for browser sessions
const extensionsService = new ExtensionsService(agb, "my_extensions");
const ext1 = await extensionsService.create("/path/to/ext1.zip");
const ext2 = await extensionsService.create("/path/to/ext2.zip");

// Create extension option for browser integration (no contextId needed!)
const extOption = extensionsService.createExtensionOption([ext1.id, ext2.id]);

// Use with BrowserContext for session creation
const browserContext = new BrowserContext({
  contextId: "browser_session",
  autoUpload: true,
  extensionOption: extOption  // All extension config encapsulated
});

Context Management:

  • If contextId provided and exists: Uses the existing context
  • If contextId provided but doesn't exist: Creates context with provided name
  • If contextId empty or not provided: Generates default name and creates context
  • No need to manually manage context creation or call initialize()
  • Context initialization happens automatically on first method call

Table of contents ​

Accessors ​

Methods ​

Accessors ​

contextId ​

• get contextId(): string

Returns ​

string

Methods ​

cleanup ​

▸ cleanup(): Promise<boolean>

Cleans up the auto-created context if it was created by this service.

Returns ​

Promise<boolean>

Promise that resolves to true if cleanup was successful or not needed, false if cleanup failed.

Note: This method only works if the context was auto-created by this service. For existing contexts, no cleanup is performed.

Example

typescript
const agb = new AGB({ apiKey: 'your_api_key' });
const service = new ExtensionsService(agb);
await service.create('/path/to/my-extension.zip');
const success = await service.cleanup();
console.log('Cleanup success:', success);

create ​

▸ create(localPath): Promise<Extension>

Uploads a new browser extension from a local path into the current context.

Parameters ​

NameTypeDescription
localPathstringPath to the local extension file (must be a .zip file).

Returns ​

Promise<Extension>

Promise that resolves to an Extension object.

Throws

If the local file doesn't exist.

Throws

If the file format is not supported (only .zip is supported).

Throws

If upload fails.

Example

typescript
const agb = new AGB({ apiKey: 'your_api_key' });
const service = new ExtensionsService(agb);
const extension = await service.create('/path/to/my-extension.zip');
console.log(`Extension ID: ${extension.id}`);
await service.cleanup();

createExtensionOption ​

▸ createExtensionOption(extensionIds): ExtensionOption

Create an ExtensionOption for the current context with specified extension IDs.

This is a convenience method that creates an ExtensionOption using the current service's contextId and the provided extension IDs. This option can then be used with BrowserContext for browser session creation.

Parameters ​

NameTypeDescription
extensionIdsstring[]List of extension IDs to include in the option. These should be extensions that exist in the current context.

Returns ​

ExtensionOption

ExtensionOption configuration object for browser extension integration.

Throws

If extensionIds is empty or invalid.

Example

typescript
// Create extensions
const ext1 = await extensionsService.create("/path/to/ext1.zip");
const ext2 = await extensionsService.create("/path/to/ext2.zip");

// Create extension option for browser integration
const extOption = extensionsService.createExtensionOption([ext1.id, ext2.id]);

// Use with BrowserContext
const browserContext = new BrowserContext({
  contextId: "browser_session",
  autoUpload: true,
  extensionContextId: extOption.contextId,
  extensionIds: extOption.extensionIds
});

delete ​

▸ delete(extensionId): Promise<boolean>

Deletes a browser extension from the current context.

Parameters ​

NameTypeDescription
extensionIdstringID of the extension to delete.

Returns ​

Promise<boolean>

Promise that resolves to true if deletion was successful, false otherwise.

Example

typescript
const agb = new AGB({ apiKey: 'your_api_key' });
const service = new ExtensionsService(agb, 'my_extensions');
const ext = await service.create('/path/to/my-extension.zip');
const success = await service.delete(ext.id);
console.log('Delete success:', success);
await service.cleanup();

list ​

▸ list(): Promise<Extension[]>

Lists all available browser extensions within this context from the cloud. Uses the context service to list files under the extensions directory.

Returns ​

Promise<Extension[]>

Promise that resolves to an array of Extension objects.

Throws

If listing extensions fails.

Example

typescript
const agb = new AGB({ apiKey: 'your_api_key' });
const service = new ExtensionsService(agb, 'my_extensions');
await service.create('/path/to/ext1.zip');
const extensions = await service.list();
console.log(`Found ${extensions.length} extensions`);
await service.cleanup();

update ​

▸ update(extensionId, newLocalPath): Promise<Extension>

Updates an existing browser extension in the current context with a new file.

Parameters ​

NameTypeDescription
extensionIdstringID of the extension to update.
newLocalPathstringPath to the new local extension file.

Returns ​

Promise<Extension>

Promise that resolves to an Extension object.

Throws

If the new local file doesn't exist.

Throws

If the extension doesn't exist in the context.

Throws

If update fails.

Example

typescript
const agb = new AGB({ apiKey: 'your_api_key' });
const service = new ExtensionsService(agb, 'my_extensions');
const ext = await service.create('/path/to/ext-v1.zip');
const updated = await service.update(ext.id, '/path/to/ext-v2.zip');
console.log('Extension updated:', updated.name);
await service.cleanup();