browser-use 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +761 -0
- package/dist/agent/cloud-events.d.ts +264 -0
- package/dist/agent/cloud-events.js +318 -0
- package/dist/agent/gif.d.ts +15 -0
- package/dist/agent/gif.js +215 -0
- package/dist/agent/index.d.ts +8 -0
- package/dist/agent/index.js +8 -0
- package/dist/agent/message-manager/service.d.ts +30 -0
- package/dist/agent/message-manager/service.js +208 -0
- package/dist/agent/message-manager/utils.d.ts +2 -0
- package/dist/agent/message-manager/utils.js +41 -0
- package/dist/agent/message-manager/views.d.ts +26 -0
- package/dist/agent/message-manager/views.js +73 -0
- package/dist/agent/prompts.d.ts +52 -0
- package/dist/agent/prompts.js +259 -0
- package/dist/agent/service.d.ts +290 -0
- package/dist/agent/service.js +2200 -0
- package/dist/agent/views.d.ts +741 -0
- package/dist/agent/views.js +537 -0
- package/dist/browser/browser.d.ts +7 -0
- package/dist/browser/browser.js +5 -0
- package/dist/browser/context.d.ts +8 -0
- package/dist/browser/context.js +4 -0
- package/dist/browser/dvd-screensaver.d.ts +101 -0
- package/dist/browser/dvd-screensaver.js +270 -0
- package/dist/browser/extensions.d.ts +63 -0
- package/dist/browser/extensions.js +359 -0
- package/dist/browser/index.d.ts +10 -0
- package/dist/browser/index.js +9 -0
- package/dist/browser/playwright-manager.d.ts +47 -0
- package/dist/browser/playwright-manager.js +146 -0
- package/dist/browser/profile.d.ts +196 -0
- package/dist/browser/profile.js +815 -0
- package/dist/browser/session.d.ts +505 -0
- package/dist/browser/session.js +3409 -0
- package/dist/browser/types.d.ts +1184 -0
- package/dist/browser/types.js +1 -0
- package/dist/browser/utils.d.ts +1 -0
- package/dist/browser/utils.js +19 -0
- package/dist/browser/views.d.ts +78 -0
- package/dist/browser/views.js +72 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +44 -0
- package/dist/config.d.ts +108 -0
- package/dist/config.js +430 -0
- package/dist/controller/index.d.ts +3 -0
- package/dist/controller/index.js +3 -0
- package/dist/controller/registry/index.d.ts +2 -0
- package/dist/controller/registry/index.js +2 -0
- package/dist/controller/registry/service.d.ts +45 -0
- package/dist/controller/registry/service.js +184 -0
- package/dist/controller/registry/views.d.ts +55 -0
- package/dist/controller/registry/views.js +174 -0
- package/dist/controller/service.d.ts +49 -0
- package/dist/controller/service.js +1176 -0
- package/dist/controller/views.d.ts +241 -0
- package/dist/controller/views.js +88 -0
- package/dist/dom/clickable-element-processor/service.d.ts +11 -0
- package/dist/dom/clickable-element-processor/service.js +60 -0
- package/dist/dom/dom_tree/index.js +1400 -0
- package/dist/dom/history-tree-processor/service.d.ts +14 -0
- package/dist/dom/history-tree-processor/service.js +75 -0
- package/dist/dom/history-tree-processor/view.d.ts +54 -0
- package/dist/dom/history-tree-processor/view.js +56 -0
- package/dist/dom/playground/extraction.d.ts +19 -0
- package/dist/dom/playground/extraction.js +187 -0
- package/dist/dom/playground/process-dom.d.ts +1 -0
- package/dist/dom/playground/process-dom.js +5 -0
- package/dist/dom/playground/test-accessibility.d.ts +44 -0
- package/dist/dom/playground/test-accessibility.js +111 -0
- package/dist/dom/service.d.ts +19 -0
- package/dist/dom/service.js +227 -0
- package/dist/dom/utils.d.ts +1 -0
- package/dist/dom/utils.js +6 -0
- package/dist/dom/views.d.ts +61 -0
- package/dist/dom/views.js +247 -0
- package/dist/event-bus.d.ts +11 -0
- package/dist/event-bus.js +19 -0
- package/dist/exceptions.d.ts +10 -0
- package/dist/exceptions.js +22 -0
- package/dist/filesystem/file-system.d.ts +68 -0
- package/dist/filesystem/file-system.js +412 -0
- package/dist/filesystem/index.d.ts +1 -0
- package/dist/filesystem/index.js +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +33 -0
- package/dist/integrations/gmail/actions.d.ts +12 -0
- package/dist/integrations/gmail/actions.js +113 -0
- package/dist/integrations/gmail/index.d.ts +2 -0
- package/dist/integrations/gmail/index.js +2 -0
- package/dist/integrations/gmail/service.d.ts +61 -0
- package/dist/integrations/gmail/service.js +260 -0
- package/dist/llm/anthropic/chat.d.ts +28 -0
- package/dist/llm/anthropic/chat.js +126 -0
- package/dist/llm/anthropic/index.d.ts +2 -0
- package/dist/llm/anthropic/index.js +2 -0
- package/dist/llm/anthropic/serializer.d.ts +68 -0
- package/dist/llm/anthropic/serializer.js +285 -0
- package/dist/llm/aws/chat-anthropic.d.ts +61 -0
- package/dist/llm/aws/chat-anthropic.js +176 -0
- package/dist/llm/aws/chat-bedrock.d.ts +15 -0
- package/dist/llm/aws/chat-bedrock.js +80 -0
- package/dist/llm/aws/index.d.ts +3 -0
- package/dist/llm/aws/index.js +3 -0
- package/dist/llm/aws/serializer.d.ts +5 -0
- package/dist/llm/aws/serializer.js +68 -0
- package/dist/llm/azure/chat.d.ts +15 -0
- package/dist/llm/azure/chat.js +83 -0
- package/dist/llm/azure/index.d.ts +1 -0
- package/dist/llm/azure/index.js +1 -0
- package/dist/llm/base.d.ts +16 -0
- package/dist/llm/base.js +1 -0
- package/dist/llm/deepseek/chat.d.ts +15 -0
- package/dist/llm/deepseek/chat.js +51 -0
- package/dist/llm/deepseek/index.d.ts +2 -0
- package/dist/llm/deepseek/index.js +2 -0
- package/dist/llm/deepseek/serializer.d.ts +6 -0
- package/dist/llm/deepseek/serializer.js +57 -0
- package/dist/llm/exceptions.d.ts +10 -0
- package/dist/llm/exceptions.js +18 -0
- package/dist/llm/google/chat.d.ts +20 -0
- package/dist/llm/google/chat.js +144 -0
- package/dist/llm/google/index.d.ts +2 -0
- package/dist/llm/google/index.js +2 -0
- package/dist/llm/google/serializer.d.ts +6 -0
- package/dist/llm/google/serializer.js +64 -0
- package/dist/llm/groq/chat.d.ts +15 -0
- package/dist/llm/groq/chat.js +52 -0
- package/dist/llm/groq/index.d.ts +3 -0
- package/dist/llm/groq/index.js +3 -0
- package/dist/llm/groq/parser.d.ts +32 -0
- package/dist/llm/groq/parser.js +189 -0
- package/dist/llm/groq/serializer.d.ts +6 -0
- package/dist/llm/groq/serializer.js +56 -0
- package/dist/llm/messages.d.ts +77 -0
- package/dist/llm/messages.js +157 -0
- package/dist/llm/ollama/chat.d.ts +15 -0
- package/dist/llm/ollama/chat.js +77 -0
- package/dist/llm/ollama/index.d.ts +2 -0
- package/dist/llm/ollama/index.js +2 -0
- package/dist/llm/ollama/serializer.d.ts +6 -0
- package/dist/llm/ollama/serializer.js +53 -0
- package/dist/llm/openai/chat.d.ts +38 -0
- package/dist/llm/openai/chat.js +174 -0
- package/dist/llm/openai/index.d.ts +3 -0
- package/dist/llm/openai/index.js +3 -0
- package/dist/llm/openai/like.d.ts +17 -0
- package/dist/llm/openai/like.js +19 -0
- package/dist/llm/openai/serializer.d.ts +6 -0
- package/dist/llm/openai/serializer.js +57 -0
- package/dist/llm/openrouter/chat.d.ts +15 -0
- package/dist/llm/openrouter/chat.js +74 -0
- package/dist/llm/openrouter/index.d.ts +2 -0
- package/dist/llm/openrouter/index.js +2 -0
- package/dist/llm/openrouter/serializer.d.ts +3 -0
- package/dist/llm/openrouter/serializer.js +3 -0
- package/dist/llm/schema.d.ts +6 -0
- package/dist/llm/schema.js +77 -0
- package/dist/llm/views.d.ts +15 -0
- package/dist/llm/views.js +12 -0
- package/dist/logging-config.d.ts +25 -0
- package/dist/logging-config.js +89 -0
- package/dist/mcp/client.d.ts +142 -0
- package/dist/mcp/client.js +638 -0
- package/dist/mcp/controller.d.ts +6 -0
- package/dist/mcp/controller.js +38 -0
- package/dist/mcp/index.d.ts +3 -0
- package/dist/mcp/index.js +3 -0
- package/dist/mcp/server.d.ts +134 -0
- package/dist/mcp/server.js +759 -0
- package/dist/observability-decorators.d.ts +158 -0
- package/dist/observability-decorators.js +286 -0
- package/dist/observability.d.ts +23 -0
- package/dist/observability.js +58 -0
- package/dist/screenshots/index.d.ts +1 -0
- package/dist/screenshots/index.js +1 -0
- package/dist/screenshots/service.d.ts +6 -0
- package/dist/screenshots/service.js +28 -0
- package/dist/sync/auth.d.ts +27 -0
- package/dist/sync/auth.js +205 -0
- package/dist/sync/index.d.ts +2 -0
- package/dist/sync/index.js +2 -0
- package/dist/sync/service.d.ts +21 -0
- package/dist/sync/service.js +146 -0
- package/dist/telemetry/index.d.ts +2 -0
- package/dist/telemetry/index.js +2 -0
- package/dist/telemetry/service.d.ts +12 -0
- package/dist/telemetry/service.js +85 -0
- package/dist/telemetry/views.d.ts +112 -0
- package/dist/telemetry/views.js +112 -0
- package/dist/tokens/index.d.ts +2 -0
- package/dist/tokens/index.js +2 -0
- package/dist/tokens/service.d.ts +35 -0
- package/dist/tokens/service.js +423 -0
- package/dist/tokens/views.d.ts +58 -0
- package/dist/tokens/views.js +1 -0
- package/dist/utils.d.ts +128 -0
- package/dist/utils.js +529 -0
- package/package.json +94 -5
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
import { type Browser, type BrowserContext, type Page, type Locator } from './types.js';
|
|
2
|
+
import { BrowserProfile, type BrowserProfileOptions, DEFAULT_BROWSER_PROFILE } from './profile.js';
|
|
3
|
+
import { BrowserStateSummary, type TabInfo } from './views.js';
|
|
4
|
+
import { DOMElementNode, type SelectorMap } from '../dom/views.js';
|
|
5
|
+
export interface BrowserSessionInit {
|
|
6
|
+
id?: string;
|
|
7
|
+
browser_profile?: BrowserProfile;
|
|
8
|
+
profile?: Partial<BrowserProfileOptions>;
|
|
9
|
+
browser?: Browser | null;
|
|
10
|
+
browser_context?: BrowserContext | null;
|
|
11
|
+
page?: Page | null;
|
|
12
|
+
title?: string | null;
|
|
13
|
+
url?: string | null;
|
|
14
|
+
wss_url?: string | null;
|
|
15
|
+
cdp_url?: string | null;
|
|
16
|
+
browser_pid?: number | null;
|
|
17
|
+
playwright?: unknown;
|
|
18
|
+
downloaded_files?: string[];
|
|
19
|
+
}
|
|
20
|
+
export interface BrowserStateOptions {
|
|
21
|
+
cache_clickable_elements_hashes?: boolean;
|
|
22
|
+
include_screenshot?: boolean;
|
|
23
|
+
signal?: AbortSignal | null;
|
|
24
|
+
}
|
|
25
|
+
export interface BrowserActionOptions {
|
|
26
|
+
signal?: AbortSignal | null;
|
|
27
|
+
}
|
|
28
|
+
export declare class BrowserSession {
|
|
29
|
+
readonly id: string;
|
|
30
|
+
readonly browser_profile: BrowserProfile;
|
|
31
|
+
browser: Browser | null;
|
|
32
|
+
browser_context: BrowserContext | null;
|
|
33
|
+
agent_current_page: Page | null;
|
|
34
|
+
human_current_page: Page | null;
|
|
35
|
+
initialized: boolean;
|
|
36
|
+
wss_url: string | null;
|
|
37
|
+
cdp_url: string | null;
|
|
38
|
+
browser_pid: number | null;
|
|
39
|
+
playwright: unknown;
|
|
40
|
+
private cachedBrowserState;
|
|
41
|
+
private _cachedClickableElementHashes;
|
|
42
|
+
private currentUrl;
|
|
43
|
+
private currentTitle;
|
|
44
|
+
private _logger;
|
|
45
|
+
private _tabCounter;
|
|
46
|
+
private _tabs;
|
|
47
|
+
private currentTabIndex;
|
|
48
|
+
private historyStack;
|
|
49
|
+
downloaded_files: string[];
|
|
50
|
+
private ownsBrowserResources;
|
|
51
|
+
private _autoDownloadPdfs;
|
|
52
|
+
private tabPages;
|
|
53
|
+
private currentPageLoadingStatus;
|
|
54
|
+
private _subprocess;
|
|
55
|
+
private _childProcesses;
|
|
56
|
+
private attachedAgentId;
|
|
57
|
+
private attachedSharedAgentIds;
|
|
58
|
+
private _stoppingPromise;
|
|
59
|
+
constructor(init?: BrowserSessionInit);
|
|
60
|
+
private _waitForStableNetwork;
|
|
61
|
+
private _setActivePage;
|
|
62
|
+
get tabs(): TabInfo[];
|
|
63
|
+
get active_tab_index(): number;
|
|
64
|
+
get active_tab(): TabInfo;
|
|
65
|
+
describe(): string;
|
|
66
|
+
get _owns_browser_resources(): boolean;
|
|
67
|
+
claim_agent(agentId: string, mode?: 'exclusive' | 'shared'): boolean;
|
|
68
|
+
claimAgent(agentId: string, mode?: 'exclusive' | 'shared'): boolean;
|
|
69
|
+
release_agent(agentId?: string): boolean;
|
|
70
|
+
releaseAgent(agentId?: string): boolean;
|
|
71
|
+
get_attached_agent_id(): string | null;
|
|
72
|
+
getAttachedAgentId(): string | null;
|
|
73
|
+
get_attached_agent_ids(): string[];
|
|
74
|
+
getAttachedAgentIds(): string[];
|
|
75
|
+
private _determineOwnership;
|
|
76
|
+
private _createAbortError;
|
|
77
|
+
private _isAbortError;
|
|
78
|
+
private _throwIfAborted;
|
|
79
|
+
private _waitWithAbort;
|
|
80
|
+
private _withAbort;
|
|
81
|
+
private _toPlaywrightOptions;
|
|
82
|
+
private _isSandboxLaunchError;
|
|
83
|
+
private _createNoSandboxLaunchOptions;
|
|
84
|
+
private _launchChromiumWithSandboxFallback;
|
|
85
|
+
private _connectionDescriptor;
|
|
86
|
+
toString(): string;
|
|
87
|
+
private get logger();
|
|
88
|
+
start(): Promise<this>;
|
|
89
|
+
/**
|
|
90
|
+
* Setup browser session by connecting to an existing browser process via PID
|
|
91
|
+
* Useful for debugging or connecting to manually launched browsers
|
|
92
|
+
* @param browserPid - Process ID of the browser to connect to
|
|
93
|
+
* @param cdpUrl - Optional CDP URL (will be discovered if not provided)
|
|
94
|
+
*/
|
|
95
|
+
setupBrowserViaBrowserPid(browserPid: number, cdpUrl?: string): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* Discover CDP URL from browser PID
|
|
98
|
+
* Tries common ports and checks for debugging endpoints
|
|
99
|
+
*/
|
|
100
|
+
private _discoverCdpUrl;
|
|
101
|
+
private _shutdown_browser_session;
|
|
102
|
+
close(): Promise<void>;
|
|
103
|
+
get_browser_state_with_recovery(options?: BrowserStateOptions): Promise<BrowserStateSummary>;
|
|
104
|
+
get_current_page(): Promise<import("playwright-core").Page | null>;
|
|
105
|
+
update_current_page(page: Page | null, title?: string | null, url?: string | null): void;
|
|
106
|
+
private _buildTabs;
|
|
107
|
+
navigate_to(url: string, options?: BrowserActionOptions): Promise<import("playwright-core").Page | null>;
|
|
108
|
+
create_new_tab(url: string, options?: BrowserActionOptions): Promise<import("playwright-core").Page | null>;
|
|
109
|
+
private _resolveTabIndex;
|
|
110
|
+
switch_to_tab(identifier: number, options?: BrowserActionOptions): Promise<import("playwright-core").Page | null>;
|
|
111
|
+
close_tab(identifier: number): Promise<void>;
|
|
112
|
+
go_back(options?: BrowserActionOptions): Promise<void>;
|
|
113
|
+
get_dom_element_by_index(_index: number, options?: BrowserActionOptions): Promise<DOMElementNode>;
|
|
114
|
+
set_downloaded_files(files: string[]): void;
|
|
115
|
+
add_downloaded_file(filePath: string): void;
|
|
116
|
+
get_downloaded_files(): string[];
|
|
117
|
+
set_auto_download_pdfs(enabled: boolean): void;
|
|
118
|
+
auto_download_pdfs(): boolean;
|
|
119
|
+
static get_unique_filename(directory: string, filename: string): Promise<string>;
|
|
120
|
+
get_selector_map(options?: BrowserActionOptions): Promise<SelectorMap>;
|
|
121
|
+
static is_file_input(node: DOMElementNode | null): boolean;
|
|
122
|
+
is_file_input(node: DOMElementNode | null): boolean;
|
|
123
|
+
find_file_upload_element_by_index(index: number, maxHeight?: number, maxDescendantDepth?: number, options?: BrowserActionOptions): Promise<DOMElementNode | null>;
|
|
124
|
+
get_locate_element(node: DOMElementNode): Promise<Locator | null>;
|
|
125
|
+
_input_text_element_node(node: DOMElementNode, text: string, options?: BrowserActionOptions): Promise<void>;
|
|
126
|
+
_click_element_node(node: DOMElementNode, options?: BrowserActionOptions): Promise<string | null>;
|
|
127
|
+
private _waitForLoad;
|
|
128
|
+
/**
|
|
129
|
+
* Get all cookies from the current browser context
|
|
130
|
+
*/
|
|
131
|
+
get_cookies(): Promise<Array<Record<string, any>>>;
|
|
132
|
+
/**
|
|
133
|
+
* Save cookies to a file (deprecated, use save_storage_state instead)
|
|
134
|
+
* @deprecated Use save_storage_state() instead
|
|
135
|
+
*/
|
|
136
|
+
save_cookies(...args: any[]): Promise<void>;
|
|
137
|
+
/**
|
|
138
|
+
* Load cookies from a file (deprecated, use load_storage_state instead)
|
|
139
|
+
* @deprecated Use load_storage_state() instead
|
|
140
|
+
*/
|
|
141
|
+
load_cookies_from_file(...args: any[]): Promise<void>;
|
|
142
|
+
/**
|
|
143
|
+
* Save the current storage state (cookies, localStorage, sessionStorage) to a file
|
|
144
|
+
*/
|
|
145
|
+
save_storage_state(filePath?: string): Promise<void>;
|
|
146
|
+
/**
|
|
147
|
+
* Load storage state (cookies, localStorage, sessionStorage) from a file
|
|
148
|
+
*/
|
|
149
|
+
load_storage_state(filePath?: string): Promise<void>;
|
|
150
|
+
/**
|
|
151
|
+
* Execute JavaScript in the current page context
|
|
152
|
+
*/
|
|
153
|
+
execute_javascript(script: string): Promise<any>;
|
|
154
|
+
/**
|
|
155
|
+
* Get comprehensive page information (size, scroll position, etc.)
|
|
156
|
+
*/
|
|
157
|
+
get_page_info(page?: Page): Promise<any>;
|
|
158
|
+
/**
|
|
159
|
+
* Get the HTML content of the current page
|
|
160
|
+
*/
|
|
161
|
+
get_page_html(): Promise<string>;
|
|
162
|
+
/**
|
|
163
|
+
* Get a debug view of the page structure including iframes
|
|
164
|
+
*/
|
|
165
|
+
get_page_structure(): Promise<string>;
|
|
166
|
+
/**
|
|
167
|
+
* Navigate forward in browser history
|
|
168
|
+
*/
|
|
169
|
+
go_forward(): Promise<void>;
|
|
170
|
+
/**
|
|
171
|
+
* Refresh the current page
|
|
172
|
+
*/
|
|
173
|
+
refresh(): Promise<void>;
|
|
174
|
+
/**
|
|
175
|
+
* Wait for an element to appear on the page
|
|
176
|
+
*/
|
|
177
|
+
wait_for_element(selector: string, timeout?: number): Promise<void>;
|
|
178
|
+
/**
|
|
179
|
+
* Take a screenshot of the current page
|
|
180
|
+
* @param full_page Whether to capture the full scrollable page
|
|
181
|
+
* @returns Base64 encoded PNG screenshot
|
|
182
|
+
*/
|
|
183
|
+
take_screenshot(full_page?: boolean): Promise<string | null>;
|
|
184
|
+
/**
|
|
185
|
+
* Add a request event listener to the current page
|
|
186
|
+
*/
|
|
187
|
+
on_request(callback: (request: any) => void | Promise<void>): Promise<void>;
|
|
188
|
+
/**
|
|
189
|
+
* Add a response event listener to the current page
|
|
190
|
+
*/
|
|
191
|
+
on_response(callback: (response: any) => void | Promise<void>): Promise<void>;
|
|
192
|
+
/**
|
|
193
|
+
* Remove a request event listener from the current page
|
|
194
|
+
*/
|
|
195
|
+
off_request(callback: (request: any) => void | Promise<void>): Promise<void>;
|
|
196
|
+
/**
|
|
197
|
+
* Remove a response event listener from the current page
|
|
198
|
+
*/
|
|
199
|
+
off_response(callback: (response: any) => void | Promise<void>): Promise<void>;
|
|
200
|
+
/**
|
|
201
|
+
* Get information about all open tabs
|
|
202
|
+
* @returns Array of tab information including page_id, url, and title
|
|
203
|
+
*/
|
|
204
|
+
get_tabs_info(): Promise<Array<{
|
|
205
|
+
page_id: number;
|
|
206
|
+
url: string;
|
|
207
|
+
title: string;
|
|
208
|
+
}>>;
|
|
209
|
+
/**
|
|
210
|
+
* Check if a page is responsive by trying to evaluate simple JavaScript
|
|
211
|
+
* @param page - The page to check
|
|
212
|
+
* @param timeout - Timeout in seconds (default: 5)
|
|
213
|
+
* @returns True if page is responsive, false otherwise
|
|
214
|
+
*/
|
|
215
|
+
_is_page_responsive(page: any, timeout?: number): Promise<boolean>;
|
|
216
|
+
/**
|
|
217
|
+
* Get scroll information for the current page
|
|
218
|
+
* @returns Object with scroll position and page dimensions
|
|
219
|
+
*/
|
|
220
|
+
get_scroll_info(): Promise<{
|
|
221
|
+
scroll_x: number;
|
|
222
|
+
scroll_y: number;
|
|
223
|
+
page_width: number;
|
|
224
|
+
page_height: number;
|
|
225
|
+
viewport_width: number;
|
|
226
|
+
viewport_height: number;
|
|
227
|
+
}>;
|
|
228
|
+
/**
|
|
229
|
+
* Get a summary of the current browser state
|
|
230
|
+
* @param cache_clickable_elements_hashes - Cache clickable element hashes to detect new elements
|
|
231
|
+
* @param include_screenshot - Include screenshot in state summary
|
|
232
|
+
* @returns BrowserStateSummary with current page state
|
|
233
|
+
*/
|
|
234
|
+
get_state_summary(cache_clickable_elements_hashes?: boolean, include_screenshot?: boolean): Promise<BrowserStateSummary>;
|
|
235
|
+
/**
|
|
236
|
+
* Get minimal state summary without DOM processing, but with screenshot
|
|
237
|
+
* Used when page is in error state or unresponsive
|
|
238
|
+
*/
|
|
239
|
+
get_minimal_state_summary(): Promise<BrowserStateSummary>;
|
|
240
|
+
/**
|
|
241
|
+
* Internal method to get updated browser state with DOM processing
|
|
242
|
+
* @param focus_element - Element index to focus on (default: -1)
|
|
243
|
+
* @param include_screenshot - Whether to include screenshot
|
|
244
|
+
*/
|
|
245
|
+
private _get_updated_state;
|
|
246
|
+
/**
|
|
247
|
+
* Check if a URL is a new tab page
|
|
248
|
+
*/
|
|
249
|
+
private _is_new_tab_page;
|
|
250
|
+
/**
|
|
251
|
+
* Check if page is displaying a PDF
|
|
252
|
+
*/
|
|
253
|
+
private _is_pdf_viewer;
|
|
254
|
+
/**
|
|
255
|
+
* Auto-download PDF if detected and auto-download is enabled
|
|
256
|
+
*/
|
|
257
|
+
private _auto_download_pdf_if_needed;
|
|
258
|
+
/**
|
|
259
|
+
* Check if an element is visible on the page
|
|
260
|
+
*/
|
|
261
|
+
private _is_visible;
|
|
262
|
+
/**
|
|
263
|
+
* Locate an element by XPath
|
|
264
|
+
*/
|
|
265
|
+
get_locate_element_by_xpath(xpath: string): Promise<any>;
|
|
266
|
+
/**
|
|
267
|
+
* Locate an element by CSS selector
|
|
268
|
+
*/
|
|
269
|
+
get_locate_element_by_css_selector(css_selector: string): Promise<any>;
|
|
270
|
+
/**
|
|
271
|
+
* Locate an element by text content
|
|
272
|
+
* @param text - Text to search for
|
|
273
|
+
* @param nth - Which matching element to return (0-based index)
|
|
274
|
+
* @param element_type - Optional tag name to filter by (e.g., 'button', 'span')
|
|
275
|
+
*/
|
|
276
|
+
get_locate_element_by_text(text: string, nth?: number, element_type?: string | null): Promise<any>;
|
|
277
|
+
/**
|
|
278
|
+
* Check if browser session is connected and has valid browser/context objects
|
|
279
|
+
* @param restart - If true, attempt to create a new tab if no pages exist
|
|
280
|
+
*/
|
|
281
|
+
is_connected(restart?: boolean): Promise<boolean>;
|
|
282
|
+
/**
|
|
283
|
+
* Check if a URL is allowed based on allowed_domains configuration
|
|
284
|
+
* @param url - URL to check
|
|
285
|
+
*/
|
|
286
|
+
private _is_url_allowed;
|
|
287
|
+
/**
|
|
288
|
+
* Navigate helper with URL validation
|
|
289
|
+
*/
|
|
290
|
+
navigate(url: string): Promise<void>;
|
|
291
|
+
/**
|
|
292
|
+
* Kill the browser session (force close even if keep_alive=true)
|
|
293
|
+
*/
|
|
294
|
+
kill(): Promise<void>;
|
|
295
|
+
/**
|
|
296
|
+
* Alias for close() to match Python API
|
|
297
|
+
*/
|
|
298
|
+
stop(): Promise<void>;
|
|
299
|
+
/**
|
|
300
|
+
* Perform a click action with download and navigation handling
|
|
301
|
+
* @param element_node - DOM element to click
|
|
302
|
+
*/
|
|
303
|
+
perform_click(element_node: DOMElementNode): Promise<string | null>;
|
|
304
|
+
/**
|
|
305
|
+
* Remove all highlights from the current page
|
|
306
|
+
*/
|
|
307
|
+
remove_highlights(): Promise<void>;
|
|
308
|
+
/**
|
|
309
|
+
* Start tracing on browser context if traces_dir is configured
|
|
310
|
+
* Note: Currently optional as it may cause performance issues in some cases
|
|
311
|
+
*/
|
|
312
|
+
private _startContextTracing;
|
|
313
|
+
/**
|
|
314
|
+
* Save browser trace recording
|
|
315
|
+
*/
|
|
316
|
+
private _saveTraceRecording;
|
|
317
|
+
/**
|
|
318
|
+
* Scroll using CDP Input.synthesizeScrollGesture for universal compatibility
|
|
319
|
+
* @param page - The page to scroll
|
|
320
|
+
* @param pixels - Number of pixels to scroll (positive = up, negative = down)
|
|
321
|
+
* @returns true if successful, false if failed
|
|
322
|
+
*/
|
|
323
|
+
private _scrollWithCdpGesture;
|
|
324
|
+
/**
|
|
325
|
+
* Scroll the current page container
|
|
326
|
+
* @param pixels - Number of pixels to scroll (positive = up, negative = down)
|
|
327
|
+
*/
|
|
328
|
+
private _scrollContainer;
|
|
329
|
+
/**
|
|
330
|
+
* Compute hashes for all clickable elements in the selector map
|
|
331
|
+
* @param selectorMap - Selector map from DOM state
|
|
332
|
+
* @returns Set of element hashes
|
|
333
|
+
*/
|
|
334
|
+
private _computeElementHashes;
|
|
335
|
+
/**
|
|
336
|
+
* Mark elements in the selector map as new if they weren't in the cached hashes
|
|
337
|
+
* @param selectorMap - Selector map to update
|
|
338
|
+
* @param cachedHashes - Previously cached element hashes
|
|
339
|
+
*/
|
|
340
|
+
private _markNewElements;
|
|
341
|
+
/**
|
|
342
|
+
* Helper to get a safe method name from the calling context
|
|
343
|
+
* Used for recovery error messages
|
|
344
|
+
*/
|
|
345
|
+
private _getCurrentMethodName;
|
|
346
|
+
/**
|
|
347
|
+
* Get current page with fallback logic
|
|
348
|
+
* Alias for compatibility with Python API
|
|
349
|
+
*/
|
|
350
|
+
getCurrentPage(): Promise<Page | null>;
|
|
351
|
+
/**
|
|
352
|
+
* Log warning about unsafe glob patterns
|
|
353
|
+
* @param pattern - The glob pattern being used
|
|
354
|
+
*/
|
|
355
|
+
private _logGlobWarning;
|
|
356
|
+
/**
|
|
357
|
+
* Create a shallow copy of the browser session
|
|
358
|
+
* Note: This doesn't copy the actual browser instance, just the session metadata
|
|
359
|
+
* @returns A new BrowserSession instance with copied state
|
|
360
|
+
*/
|
|
361
|
+
modelCopy(): BrowserSession;
|
|
362
|
+
model_copy(): BrowserSession;
|
|
363
|
+
private _inRecovery;
|
|
364
|
+
/**
|
|
365
|
+
* Check if a page is responsive by trying to evaluate simple JavaScript
|
|
366
|
+
* @param page - The page to check
|
|
367
|
+
* @param timeout - Timeout in seconds (default: 5.0)
|
|
368
|
+
* @returns true if page is responsive, false otherwise
|
|
369
|
+
*/
|
|
370
|
+
private _isPageResponsive;
|
|
371
|
+
/**
|
|
372
|
+
* Force close a crashed page using CDP from a clean temporary page
|
|
373
|
+
* @param pageUrl - The URL of the page to force close
|
|
374
|
+
* @returns true if successful, false otherwise
|
|
375
|
+
*/
|
|
376
|
+
private _forceClosePageViaCdp;
|
|
377
|
+
/**
|
|
378
|
+
* Try to reopen a URL in a new page and check if it's responsive
|
|
379
|
+
* @param url - The URL to reopen
|
|
380
|
+
* @param timeoutMs - Navigation timeout in milliseconds
|
|
381
|
+
* @returns true if successful and responsive, false otherwise
|
|
382
|
+
*/
|
|
383
|
+
private _tryReopenUrl;
|
|
384
|
+
/**
|
|
385
|
+
* Create a new blank page as a fallback when recovery fails
|
|
386
|
+
* @param url - The original URL that failed
|
|
387
|
+
*/
|
|
388
|
+
private _createBlankFallbackPage;
|
|
389
|
+
/**
|
|
390
|
+
* Recover from an unresponsive page by closing and reopening it
|
|
391
|
+
* @param callingMethod - The name of the method that detected the unresponsive page
|
|
392
|
+
* @param timeoutMs - Navigation timeout in milliseconds
|
|
393
|
+
*/
|
|
394
|
+
private _recoverUnresponsivePage;
|
|
395
|
+
/**
|
|
396
|
+
* Generate enhanced CSS selector for an element
|
|
397
|
+
* Handles special characters and provides fallback strategies
|
|
398
|
+
* @param xpath - XPath of the element
|
|
399
|
+
* @param element - Optional element node for additional context
|
|
400
|
+
* @returns Enhanced CSS selector string
|
|
401
|
+
*/
|
|
402
|
+
private _enhancedCssSelectorForElement;
|
|
403
|
+
/**
|
|
404
|
+
* Convert XPath to CSS selector
|
|
405
|
+
* Handles simple XPath expressions
|
|
406
|
+
*/
|
|
407
|
+
private _xpathToCss;
|
|
408
|
+
/**
|
|
409
|
+
* Escape special characters in CSS selectors
|
|
410
|
+
* Handles characters that need escaping in CSS
|
|
411
|
+
*/
|
|
412
|
+
private _escapeSelector;
|
|
413
|
+
/**
|
|
414
|
+
* Prepare user data directory for browser profile
|
|
415
|
+
* Handles singleton lock conflicts and creates temp profiles if needed
|
|
416
|
+
*/
|
|
417
|
+
prepareUserDataDir(userDataDir?: string): Promise<string>;
|
|
418
|
+
/**
|
|
419
|
+
* Check if user data directory has a singleton lock
|
|
420
|
+
* This happens when another Chrome instance is using the profile
|
|
421
|
+
*/
|
|
422
|
+
private _checkForSingletonLockConflict;
|
|
423
|
+
/**
|
|
424
|
+
* Fallback to a temporary profile when the primary one is locked
|
|
425
|
+
*/
|
|
426
|
+
private _fallbackToTempProfile;
|
|
427
|
+
/**
|
|
428
|
+
* Create a temporary user data directory
|
|
429
|
+
*/
|
|
430
|
+
private _createTempUserDataDir;
|
|
431
|
+
/**
|
|
432
|
+
* Setup listeners for page visibility changes
|
|
433
|
+
* Tracks when user switches tabs to update human_current_page
|
|
434
|
+
*/
|
|
435
|
+
private _setupCurrentPageChangeListeners;
|
|
436
|
+
/**
|
|
437
|
+
* Callback when tab visibility changes
|
|
438
|
+
* Updates human_current_page to reflect which tab the user is viewing
|
|
439
|
+
*/
|
|
440
|
+
private _onTabVisibilityChange;
|
|
441
|
+
/**
|
|
442
|
+
* Kill all child processes spawned by this browser session
|
|
443
|
+
*/
|
|
444
|
+
private _killChildProcesses;
|
|
445
|
+
/**
|
|
446
|
+
* Terminate the browser process and all its children
|
|
447
|
+
*/
|
|
448
|
+
private _terminateBrowserProcess;
|
|
449
|
+
/**
|
|
450
|
+
* Get child processes of a given PID
|
|
451
|
+
* Cross-platform implementation using ps on Unix-like systems and WMIC on Windows
|
|
452
|
+
*/
|
|
453
|
+
private _getChildProcesses;
|
|
454
|
+
/**
|
|
455
|
+
* Track a child process
|
|
456
|
+
*/
|
|
457
|
+
private _trackChildProcess;
|
|
458
|
+
/**
|
|
459
|
+
* Untrack a child process
|
|
460
|
+
*/
|
|
461
|
+
private _untrackChildProcess;
|
|
462
|
+
/**
|
|
463
|
+
* Show DVD screensaver loading animation
|
|
464
|
+
* Returns a function to stop the animation
|
|
465
|
+
*
|
|
466
|
+
* @param message - Message to display (default: 'Loading...')
|
|
467
|
+
* @param fps - Frames per second (default: 10)
|
|
468
|
+
* @returns Function to stop the animation
|
|
469
|
+
*
|
|
470
|
+
* @example
|
|
471
|
+
* const stopAnimation = this._showDvdScreensaverLoadingAnimation('Loading page...');
|
|
472
|
+
* await someLongOperation();
|
|
473
|
+
* stopAnimation();
|
|
474
|
+
*/
|
|
475
|
+
_showDvdScreensaverLoadingAnimation(message?: string, fps?: number): () => void;
|
|
476
|
+
/**
|
|
477
|
+
* Show simple spinner loading animation
|
|
478
|
+
* Returns a function to stop the animation
|
|
479
|
+
*
|
|
480
|
+
* @param message - Message to display (default: 'Loading...')
|
|
481
|
+
* @param fps - Frames per second (default: 10)
|
|
482
|
+
* @returns Function to stop the animation
|
|
483
|
+
*
|
|
484
|
+
* @example
|
|
485
|
+
* const stopSpinner = this._showSpinnerLoadingAnimation('Processing...');
|
|
486
|
+
* await someLongOperation();
|
|
487
|
+
* stopSpinner();
|
|
488
|
+
*/
|
|
489
|
+
_showSpinnerLoadingAnimation(message?: string, fps?: number): () => void;
|
|
490
|
+
/**
|
|
491
|
+
* Execute an async operation with DVD screensaver animation
|
|
492
|
+
*
|
|
493
|
+
* @param operation - Async operation to execute
|
|
494
|
+
* @param message - Message to display during operation
|
|
495
|
+
* @returns Result of the operation
|
|
496
|
+
*
|
|
497
|
+
* @example
|
|
498
|
+
* const page = await this._withDvdScreensaver(
|
|
499
|
+
* async () => await this.browser_context!.newPage(),
|
|
500
|
+
* 'Opening new page...'
|
|
501
|
+
* );
|
|
502
|
+
*/
|
|
503
|
+
_withDvdScreensaver<T>(operation: () => Promise<T>, message?: string): Promise<T>;
|
|
504
|
+
}
|
|
505
|
+
export { DEFAULT_BROWSER_PROFILE };
|