Class: Browser
Represents a browser session using Puppeteer. Manages the creation of new browser pages and handles the browser instance.
Constructors
new Browser()
new Browser(
browser:Browser,agent:Agent,logger?:Logger,opts?: {apiKey:string;disableMemory:boolean;endpoint:string;inventory:Inventory;mode:BrowserMode; }):Browser
Initializes a new instance of the Browser class.
Parameters
| Parameter | Type | Description |
|---|---|---|
browser | Browser | The Puppeteer browser instance. |
agent | Agent | The agent instance that interacts with the browser. |
logger? | Logger | Optional logger for logging browser activities. |
opts? | object | Optional configuration options for the browser. |
opts.apiKey? | string | The API key for the browser. |
opts.disableMemory? | boolean | Specifies if the browser should disable memory. |
opts.endpoint? | string | The HDR collective memory endpoint. |
opts.inventory? | Inventory | The inventory to use for the browser. |
opts.mode? | BrowserMode | The mode of the browser (e.g., text). |
Returns
Defined in
Properties
agent
agent:
Agent
The agent instance that interacts with the browser.
Defined in
browser
browser:
Browser
The Puppeteer browser instance.
Defined in
logger?
optionallogger:Logger
Optional logger for logging browser activities.
Defined in
mode
mode:
BrowserMode
The mode of the browser which could be headless or non-headless.
Defined in
pages
pages:
Map<string,Page>
Defined in
Methods
close()
close():
Promise<void>
Closes all pages and the browser instance.
Returns
Promise<void>
A promise that resolves when all pages and the browser have been closed.
Defined in
newPage()
newPage(
opts?: {agent:Agent;device:Device;disableMemory:boolean;inventory:Inventory;pageId:string; }):Promise<Page>
Asynchronously creates and returns a new Page instance, potentially emulating a specific device.
Parameters
| Parameter | Type |
|---|---|
opts? | object |
opts.agent? | Agent |
opts.device? | Device |
opts.disableMemory? | boolean |
opts.inventory? | Inventory |
opts.pageId? | string |
Returns
Promise<Page>
A promise that resolves to the newly created Page instance.
Defined in
launch()
staticlaunch(headless:boolean,agent:Agent,logger?:Logger,opts?: {apiKey:string;browserLaunchArgs:string[];browserWSEndpoint:string;disableMemory:boolean;endpoint:string;inventory:Inventory;mode:BrowserMode; }):Promise<Browser>
Asynchronously launch a new Browser instance with given configuration.
Parameters
| Parameter | Type | Description |
|---|---|---|
headless | boolean | Specifies if the browser should be launched in headless mode. |
agent | Agent | The agent that will interact with the browser. |
logger? | Logger | Optional logger to pass for browser operation logs. |
opts? | object | Optional configuration options for launching the browser. |
opts.apiKey? | string | The API key for the browser. |
opts.browserLaunchArgs? | string[] | Additional arguments for launching the browser. |
opts.browserWSEndpoint? | string | The WebSocket endpoint to connect to a browser instance. |
opts.disableMemory? | boolean | Specifies if the browser should disable memory. |
opts.endpoint? | string | The HDR collective memory endpoint. |
opts.inventory? | Inventory | The inventory to use for the browser. |
opts.mode? | BrowserMode | The mode of the browser, defaults to text. |
Returns
Promise<Browser>
A promise that resolves to an instance of Browser.