Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/browserView/common/browserView.ts
5221 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { Event } from '../../../base/common/event.js';
7
import { VSBuffer } from '../../../base/common/buffer.js';
8
import { URI } from '../../../base/common/uri.js';
9
10
export interface IBrowserViewBounds {
11
windowId: number;
12
x: number;
13
y: number;
14
width: number;
15
height: number;
16
zoomFactor: number;
17
}
18
19
export interface IBrowserViewCaptureScreenshotOptions {
20
quality?: number;
21
rect?: { x: number; y: number; width: number; height: number };
22
}
23
24
export interface IBrowserViewState {
25
url: string;
26
title: string;
27
canGoBack: boolean;
28
canGoForward: boolean;
29
loading: boolean;
30
focused: boolean;
31
visible: boolean;
32
isDevToolsOpen: boolean;
33
lastScreenshot: VSBuffer | undefined;
34
lastFavicon: string | undefined;
35
lastError: IBrowserViewLoadError | undefined;
36
storageScope: BrowserViewStorageScope;
37
}
38
39
export interface IBrowserViewNavigationEvent {
40
url: string;
41
canGoBack: boolean;
42
canGoForward: boolean;
43
}
44
45
export interface IBrowserViewLoadingEvent {
46
loading: boolean;
47
error?: IBrowserViewLoadError;
48
}
49
50
export interface IBrowserViewLoadError {
51
url: string;
52
errorCode: number;
53
errorDescription: string;
54
}
55
56
export interface IBrowserViewFocusEvent {
57
focused: boolean;
58
}
59
60
export interface IBrowserViewVisibilityEvent {
61
visible: boolean;
62
}
63
64
export interface IBrowserViewDevToolsStateEvent {
65
isDevToolsOpen: boolean;
66
}
67
68
export interface IBrowserViewKeyDownEvent {
69
key: string;
70
keyCode: number;
71
code: string;
72
ctrlKey: boolean;
73
shiftKey: boolean;
74
altKey: boolean;
75
metaKey: boolean;
76
repeat: boolean;
77
}
78
79
export interface IBrowserViewTitleChangeEvent {
80
title: string;
81
}
82
83
export interface IBrowserViewFaviconChangeEvent {
84
favicon: string;
85
}
86
87
export enum BrowserNewPageLocation {
88
Foreground = 'foreground',
89
Background = 'background',
90
NewWindow = 'newWindow'
91
}
92
export interface IBrowserViewNewPageRequest {
93
resource: URI;
94
location: BrowserNewPageLocation;
95
// Only applicable if location is NewWindow
96
position?: { x?: number; y?: number; width?: number; height?: number };
97
}
98
99
export interface IBrowserViewFindInPageOptions {
100
recompute?: boolean;
101
forward?: boolean;
102
matchCase?: boolean;
103
}
104
105
export interface IBrowserViewFindInPageResult {
106
activeMatchOrdinal: number;
107
matches: number;
108
selectionArea?: { x: number; y: number; width: number; height: number };
109
finalUpdate: boolean;
110
}
111
112
export enum BrowserViewStorageScope {
113
Global = 'global',
114
Workspace = 'workspace',
115
Ephemeral = 'ephemeral'
116
}
117
118
export const ipcBrowserViewChannelName = 'browserView';
119
120
/**
121
* This should match the isolated world ID defined in `preload-browserView.ts`.
122
*/
123
export const browserViewIsolatedWorldId = 999;
124
125
export interface IBrowserViewService {
126
/**
127
* Dynamic events that return an Event for a specific browser view ID.
128
*/
129
onDynamicDidNavigate(id: string): Event<IBrowserViewNavigationEvent>;
130
onDynamicDidChangeLoadingState(id: string): Event<IBrowserViewLoadingEvent>;
131
onDynamicDidChangeFocus(id: string): Event<IBrowserViewFocusEvent>;
132
onDynamicDidChangeVisibility(id: string): Event<IBrowserViewVisibilityEvent>;
133
onDynamicDidChangeDevToolsState(id: string): Event<IBrowserViewDevToolsStateEvent>;
134
onDynamicDidKeyCommand(id: string): Event<IBrowserViewKeyDownEvent>;
135
onDynamicDidChangeTitle(id: string): Event<IBrowserViewTitleChangeEvent>;
136
onDynamicDidChangeFavicon(id: string): Event<IBrowserViewFaviconChangeEvent>;
137
onDynamicDidRequestNewPage(id: string): Event<IBrowserViewNewPageRequest>;
138
onDynamicDidFindInPage(id: string): Event<IBrowserViewFindInPageResult>;
139
onDynamicDidClose(id: string): Event<void>;
140
141
/**
142
* Get or create a browser view instance
143
* @param id The browser view identifier
144
* @param scope The storage scope for the browser view. Ignored if the view already exists.
145
* @param workspaceId Workspace identifier for session isolation. Only used if scope is 'workspace'.
146
*/
147
getOrCreateBrowserView(id: string, scope: BrowserViewStorageScope, workspaceId?: string): Promise<IBrowserViewState>;
148
149
/**
150
* Destroy a browser view instance
151
* @param id The browser view identifier
152
*/
153
destroyBrowserView(id: string): Promise<void>;
154
155
/**
156
* Update the bounds of a browser view
157
* @param id The browser view identifier
158
* @param bounds The new bounds for the view
159
*/
160
layout(id: string, bounds: IBrowserViewBounds): Promise<void>;
161
162
/**
163
* Set the visibility of a browser view
164
* @param id The browser view identifier
165
* @param visible Whether the view should be visible
166
*/
167
setVisible(id: string, visible: boolean): Promise<void>;
168
169
/**
170
* Navigate the browser view to a URL
171
* @param id The browser view identifier
172
* @param url The URL to navigate to
173
*/
174
loadURL(id: string, url: string): Promise<void>;
175
176
/**
177
* Get the current URL of a browser view
178
* @param id The browser view identifier
179
*/
180
getURL(id: string): Promise<string>;
181
182
/**
183
* Go back in navigation history
184
* @param id The browser view identifier
185
*/
186
goBack(id: string): Promise<void>;
187
188
/**
189
* Go forward in navigation history
190
* @param id The browser view identifier
191
*/
192
goForward(id: string): Promise<void>;
193
194
/**
195
* Reload the current page
196
* @param id The browser view identifier
197
*/
198
reload(id: string): Promise<void>;
199
200
/**
201
* Toggle developer tools for the browser view.
202
* @param id The browser view identifier
203
*/
204
toggleDevTools(id: string): Promise<void>;
205
206
/**
207
* Check if the view can go back
208
* @param id The browser view identifier
209
*/
210
canGoBack(id: string): Promise<boolean>;
211
212
/**
213
* Check if the view can go forward
214
* @param id The browser view identifier
215
*/
216
canGoForward(id: string): Promise<boolean>;
217
218
/**
219
* Capture a screenshot of the browser view
220
* @param id The browser view identifier
221
* @param options Screenshot options (quality and rect)
222
* @returns Screenshot as a buffer
223
*/
224
captureScreenshot(id: string, options?: IBrowserViewCaptureScreenshotOptions): Promise<VSBuffer>;
225
226
/**
227
* Dispatch a key event to the browser view
228
* @param id The browser view identifier
229
* @param keyEvent The key event data
230
*/
231
dispatchKeyEvent(id: string, keyEvent: IBrowserViewKeyDownEvent): Promise<void>;
232
233
/**
234
* Focus the browser view
235
* @param id The browser view identifier
236
*/
237
focus(id: string): Promise<void>;
238
239
/**
240
* Find text in the browser view's page
241
* @param id The browser view identifier
242
* @param text The text to search for
243
* @param options Find options (forward direction, find next)
244
*/
245
findInPage(id: string, text: string, options?: IBrowserViewFindInPageOptions): Promise<void>;
246
247
/**
248
* Stop the find in page session
249
* @param id The browser view identifier
250
* @param keepSelection Whether to keep the current selection
251
*/
252
stopFindInPage(id: string, keepSelection?: boolean): Promise<void>;
253
254
/**
255
* Get the currently selected text in the browser view.
256
* Returns immediately with empty string if the page is still loading.
257
* @param id The browser view identifier
258
* @returns The selected text, or empty string if no selection or page is loading
259
*/
260
getSelectedText(id: string): Promise<string>;
261
262
/**
263
* Clear all storage data for the global browser session
264
*/
265
clearGlobalStorage(): Promise<void>;
266
267
/**
268
* Clear all storage data for a specific workspace browser session
269
* @param workspaceId The workspace identifier
270
*/
271
clearWorkspaceStorage(workspaceId: string): Promise<void>;
272
273
/**
274
* Clear storage data for a specific browser view
275
* @param id The browser view identifier
276
*/
277
clearStorage(id: string): Promise<void>;
278
}
279
280