Path: blob/main/src/vs/platform/browserView/common/browserView.ts
4777 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { Event } from '../../../base/common/event.js';6import { VSBuffer } from '../../../base/common/buffer.js';78export interface IBrowserViewBounds {9windowId: number;10x: number;11y: number;12width: number;13height: number;14zoomFactor: number;15}1617export interface IBrowserViewCaptureScreenshotOptions {18quality?: number;19rect?: { x: number; y: number; width: number; height: number };20}2122export interface IBrowserViewState {23url: string;24title: string;25canGoBack: boolean;26canGoForward: boolean;27loading: boolean;28isDevToolsOpen: boolean;29lastScreenshot: VSBuffer | undefined;30lastFavicon: string | undefined;31lastError: IBrowserViewLoadError | undefined;32storageScope: BrowserViewStorageScope;33}3435export interface IBrowserViewNavigationEvent {36url: string;37canGoBack: boolean;38canGoForward: boolean;39}4041export interface IBrowserViewLoadingEvent {42loading: boolean;43error?: IBrowserViewLoadError;44}4546export interface IBrowserViewLoadError {47url: string;48errorCode: number;49errorDescription: string;50}5152export interface IBrowserViewFocusEvent {53focused: boolean;54}5556export interface IBrowserViewDevToolsStateEvent {57isDevToolsOpen: boolean;58}5960export interface IBrowserViewKeyDownEvent {61key: string;62keyCode: number;63code: string;64ctrlKey: boolean;65shiftKey: boolean;66altKey: boolean;67metaKey: boolean;68repeat: boolean;69}7071export interface IBrowserViewTitleChangeEvent {72title: string;73}7475export interface IBrowserViewFaviconChangeEvent {76favicon: string;77}7879export interface IBrowserViewNewPageRequest {80url: string;81name?: string;82background: boolean;83}8485export enum BrowserViewStorageScope {86Global = 'global',87Workspace = 'workspace',88Ephemeral = 'ephemeral'89}9091export const ipcBrowserViewChannelName = 'browserView';9293export interface IBrowserViewService {94/**95* Dynamic events that return an Event for a specific browser view ID.96*/97onDynamicDidNavigate(id: string): Event<IBrowserViewNavigationEvent>;98onDynamicDidChangeLoadingState(id: string): Event<IBrowserViewLoadingEvent>;99onDynamicDidChangeFocus(id: string): Event<IBrowserViewFocusEvent>;100onDynamicDidChangeDevToolsState(id: string): Event<IBrowserViewDevToolsStateEvent>;101onDynamicDidKeyCommand(id: string): Event<IBrowserViewKeyDownEvent>;102onDynamicDidChangeTitle(id: string): Event<IBrowserViewTitleChangeEvent>;103onDynamicDidChangeFavicon(id: string): Event<IBrowserViewFaviconChangeEvent>;104onDynamicDidRequestNewPage(id: string): Event<IBrowserViewNewPageRequest>;105onDynamicDidClose(id: string): Event<void>;106107/**108* Get or create a browser view instance109* @param id The browser view identifier110* @param scope The storage scope for the browser view. Ignored if the view already exists.111* @param workspaceId Workspace identifier for session isolation. Only used if scope is 'workspace'.112*/113getOrCreateBrowserView(id: string, scope: BrowserViewStorageScope, workspaceId?: string): Promise<IBrowserViewState>;114115/**116* Destroy a browser view instance117* @param id The browser view identifier118*/119destroyBrowserView(id: string): Promise<void>;120121/**122* Update the bounds of a browser view123* @param id The browser view identifier124* @param bounds The new bounds for the view125*/126layout(id: string, bounds: IBrowserViewBounds): Promise<void>;127128/**129* Set the visibility of a browser view130* @param id The browser view identifier131* @param visible Whether the view should be visible132*/133setVisible(id: string, visible: boolean): Promise<void>;134135/**136* Navigate the browser view to a URL137* @param id The browser view identifier138* @param url The URL to navigate to139*/140loadURL(id: string, url: string): Promise<void>;141142/**143* Get the current URL of a browser view144* @param id The browser view identifier145*/146getURL(id: string): Promise<string>;147148/**149* Go back in navigation history150* @param id The browser view identifier151*/152goBack(id: string): Promise<void>;153154/**155* Go forward in navigation history156* @param id The browser view identifier157*/158goForward(id: string): Promise<void>;159160/**161* Reload the current page162* @param id The browser view identifier163*/164reload(id: string): Promise<void>;165166/**167* Toggle developer tools for the browser view.168* @param id The browser view identifier169*/170toggleDevTools(id: string): Promise<void>;171172/**173* Check if the view can go back174* @param id The browser view identifier175*/176canGoBack(id: string): Promise<boolean>;177178/**179* Check if the view can go forward180* @param id The browser view identifier181*/182canGoForward(id: string): Promise<boolean>;183184/**185* Capture a screenshot of the browser view186* @param id The browser view identifier187* @param options Screenshot options (quality and rect)188* @returns Screenshot as a buffer189*/190captureScreenshot(id: string, options?: IBrowserViewCaptureScreenshotOptions): Promise<VSBuffer>;191192/**193* Dispatch a key event to the browser view194* @param id The browser view identifier195* @param keyEvent The key event data196*/197dispatchKeyEvent(id: string, keyEvent: IBrowserViewKeyDownEvent): Promise<void>;198199/**200* Focus the browser view201* @param id The browser view identifier202*/203focus(id: string): Promise<void>;204205/**206* Clear all storage data for the global browser session207*/208clearGlobalStorage(): Promise<void>;209210/**211* Clear all storage data for a specific workspace browser session212* @param workspaceId The workspace identifier213*/214clearWorkspaceStorage(workspaceId: string): Promise<void>;215}216217218