Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/browserView/common/browserView.ts
4777 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
9
export interface IBrowserViewBounds {
10
windowId: number;
11
x: number;
12
y: number;
13
width: number;
14
height: number;
15
zoomFactor: number;
16
}
17
18
export interface IBrowserViewCaptureScreenshotOptions {
19
quality?: number;
20
rect?: { x: number; y: number; width: number; height: number };
21
}
22
23
export interface IBrowserViewState {
24
url: string;
25
title: string;
26
canGoBack: boolean;
27
canGoForward: boolean;
28
loading: boolean;
29
isDevToolsOpen: boolean;
30
lastScreenshot: VSBuffer | undefined;
31
lastFavicon: string | undefined;
32
lastError: IBrowserViewLoadError | undefined;
33
storageScope: BrowserViewStorageScope;
34
}
35
36
export interface IBrowserViewNavigationEvent {
37
url: string;
38
canGoBack: boolean;
39
canGoForward: boolean;
40
}
41
42
export interface IBrowserViewLoadingEvent {
43
loading: boolean;
44
error?: IBrowserViewLoadError;
45
}
46
47
export interface IBrowserViewLoadError {
48
url: string;
49
errorCode: number;
50
errorDescription: string;
51
}
52
53
export interface IBrowserViewFocusEvent {
54
focused: boolean;
55
}
56
57
export interface IBrowserViewDevToolsStateEvent {
58
isDevToolsOpen: boolean;
59
}
60
61
export interface IBrowserViewKeyDownEvent {
62
key: string;
63
keyCode: number;
64
code: string;
65
ctrlKey: boolean;
66
shiftKey: boolean;
67
altKey: boolean;
68
metaKey: boolean;
69
repeat: boolean;
70
}
71
72
export interface IBrowserViewTitleChangeEvent {
73
title: string;
74
}
75
76
export interface IBrowserViewFaviconChangeEvent {
77
favicon: string;
78
}
79
80
export interface IBrowserViewNewPageRequest {
81
url: string;
82
name?: string;
83
background: boolean;
84
}
85
86
export enum BrowserViewStorageScope {
87
Global = 'global',
88
Workspace = 'workspace',
89
Ephemeral = 'ephemeral'
90
}
91
92
export const ipcBrowserViewChannelName = 'browserView';
93
94
export interface IBrowserViewService {
95
/**
96
* Dynamic events that return an Event for a specific browser view ID.
97
*/
98
onDynamicDidNavigate(id: string): Event<IBrowserViewNavigationEvent>;
99
onDynamicDidChangeLoadingState(id: string): Event<IBrowserViewLoadingEvent>;
100
onDynamicDidChangeFocus(id: string): Event<IBrowserViewFocusEvent>;
101
onDynamicDidChangeDevToolsState(id: string): Event<IBrowserViewDevToolsStateEvent>;
102
onDynamicDidKeyCommand(id: string): Event<IBrowserViewKeyDownEvent>;
103
onDynamicDidChangeTitle(id: string): Event<IBrowserViewTitleChangeEvent>;
104
onDynamicDidChangeFavicon(id: string): Event<IBrowserViewFaviconChangeEvent>;
105
onDynamicDidRequestNewPage(id: string): Event<IBrowserViewNewPageRequest>;
106
onDynamicDidClose(id: string): Event<void>;
107
108
/**
109
* Get or create a browser view instance
110
* @param id The browser view identifier
111
* @param scope The storage scope for the browser view. Ignored if the view already exists.
112
* @param workspaceId Workspace identifier for session isolation. Only used if scope is 'workspace'.
113
*/
114
getOrCreateBrowserView(id: string, scope: BrowserViewStorageScope, workspaceId?: string): Promise<IBrowserViewState>;
115
116
/**
117
* Destroy a browser view instance
118
* @param id The browser view identifier
119
*/
120
destroyBrowserView(id: string): Promise<void>;
121
122
/**
123
* Update the bounds of a browser view
124
* @param id The browser view identifier
125
* @param bounds The new bounds for the view
126
*/
127
layout(id: string, bounds: IBrowserViewBounds): Promise<void>;
128
129
/**
130
* Set the visibility of a browser view
131
* @param id The browser view identifier
132
* @param visible Whether the view should be visible
133
*/
134
setVisible(id: string, visible: boolean): Promise<void>;
135
136
/**
137
* Navigate the browser view to a URL
138
* @param id The browser view identifier
139
* @param url The URL to navigate to
140
*/
141
loadURL(id: string, url: string): Promise<void>;
142
143
/**
144
* Get the current URL of a browser view
145
* @param id The browser view identifier
146
*/
147
getURL(id: string): Promise<string>;
148
149
/**
150
* Go back in navigation history
151
* @param id The browser view identifier
152
*/
153
goBack(id: string): Promise<void>;
154
155
/**
156
* Go forward in navigation history
157
* @param id The browser view identifier
158
*/
159
goForward(id: string): Promise<void>;
160
161
/**
162
* Reload the current page
163
* @param id The browser view identifier
164
*/
165
reload(id: string): Promise<void>;
166
167
/**
168
* Toggle developer tools for the browser view.
169
* @param id The browser view identifier
170
*/
171
toggleDevTools(id: string): Promise<void>;
172
173
/**
174
* Check if the view can go back
175
* @param id The browser view identifier
176
*/
177
canGoBack(id: string): Promise<boolean>;
178
179
/**
180
* Check if the view can go forward
181
* @param id The browser view identifier
182
*/
183
canGoForward(id: string): Promise<boolean>;
184
185
/**
186
* Capture a screenshot of the browser view
187
* @param id The browser view identifier
188
* @param options Screenshot options (quality and rect)
189
* @returns Screenshot as a buffer
190
*/
191
captureScreenshot(id: string, options?: IBrowserViewCaptureScreenshotOptions): Promise<VSBuffer>;
192
193
/**
194
* Dispatch a key event to the browser view
195
* @param id The browser view identifier
196
* @param keyEvent The key event data
197
*/
198
dispatchKeyEvent(id: string, keyEvent: IBrowserViewKeyDownEvent): Promise<void>;
199
200
/**
201
* Focus the browser view
202
* @param id The browser view identifier
203
*/
204
focus(id: string): Promise<void>;
205
206
/**
207
* Clear all storage data for the global browser session
208
*/
209
clearGlobalStorage(): Promise<void>;
210
211
/**
212
* Clear all storage data for a specific workspace browser session
213
* @param workspaceId The workspace identifier
214
*/
215
clearWorkspaceStorage(workspaceId: string): Promise<void>;
216
}
217
218