Path: blob/main/src/vs/platform/browserView/common/browserView.ts
5221 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';7import { URI } from '../../../base/common/uri.js';89export interface IBrowserViewBounds {10windowId: number;11x: number;12y: number;13width: number;14height: number;15zoomFactor: number;16}1718export interface IBrowserViewCaptureScreenshotOptions {19quality?: number;20rect?: { x: number; y: number; width: number; height: number };21}2223export interface IBrowserViewState {24url: string;25title: string;26canGoBack: boolean;27canGoForward: boolean;28loading: boolean;29focused: boolean;30visible: boolean;31isDevToolsOpen: boolean;32lastScreenshot: VSBuffer | undefined;33lastFavicon: string | undefined;34lastError: IBrowserViewLoadError | undefined;35storageScope: BrowserViewStorageScope;36}3738export interface IBrowserViewNavigationEvent {39url: string;40canGoBack: boolean;41canGoForward: boolean;42}4344export interface IBrowserViewLoadingEvent {45loading: boolean;46error?: IBrowserViewLoadError;47}4849export interface IBrowserViewLoadError {50url: string;51errorCode: number;52errorDescription: string;53}5455export interface IBrowserViewFocusEvent {56focused: boolean;57}5859export interface IBrowserViewVisibilityEvent {60visible: boolean;61}6263export interface IBrowserViewDevToolsStateEvent {64isDevToolsOpen: boolean;65}6667export interface IBrowserViewKeyDownEvent {68key: string;69keyCode: number;70code: string;71ctrlKey: boolean;72shiftKey: boolean;73altKey: boolean;74metaKey: boolean;75repeat: boolean;76}7778export interface IBrowserViewTitleChangeEvent {79title: string;80}8182export interface IBrowserViewFaviconChangeEvent {83favicon: string;84}8586export enum BrowserNewPageLocation {87Foreground = 'foreground',88Background = 'background',89NewWindow = 'newWindow'90}91export interface IBrowserViewNewPageRequest {92resource: URI;93location: BrowserNewPageLocation;94// Only applicable if location is NewWindow95position?: { x?: number; y?: number; width?: number; height?: number };96}9798export interface IBrowserViewFindInPageOptions {99recompute?: boolean;100forward?: boolean;101matchCase?: boolean;102}103104export interface IBrowserViewFindInPageResult {105activeMatchOrdinal: number;106matches: number;107selectionArea?: { x: number; y: number; width: number; height: number };108finalUpdate: boolean;109}110111export enum BrowserViewStorageScope {112Global = 'global',113Workspace = 'workspace',114Ephemeral = 'ephemeral'115}116117export const ipcBrowserViewChannelName = 'browserView';118119/**120* This should match the isolated world ID defined in `preload-browserView.ts`.121*/122export const browserViewIsolatedWorldId = 999;123124export interface IBrowserViewService {125/**126* Dynamic events that return an Event for a specific browser view ID.127*/128onDynamicDidNavigate(id: string): Event<IBrowserViewNavigationEvent>;129onDynamicDidChangeLoadingState(id: string): Event<IBrowserViewLoadingEvent>;130onDynamicDidChangeFocus(id: string): Event<IBrowserViewFocusEvent>;131onDynamicDidChangeVisibility(id: string): Event<IBrowserViewVisibilityEvent>;132onDynamicDidChangeDevToolsState(id: string): Event<IBrowserViewDevToolsStateEvent>;133onDynamicDidKeyCommand(id: string): Event<IBrowserViewKeyDownEvent>;134onDynamicDidChangeTitle(id: string): Event<IBrowserViewTitleChangeEvent>;135onDynamicDidChangeFavicon(id: string): Event<IBrowserViewFaviconChangeEvent>;136onDynamicDidRequestNewPage(id: string): Event<IBrowserViewNewPageRequest>;137onDynamicDidFindInPage(id: string): Event<IBrowserViewFindInPageResult>;138onDynamicDidClose(id: string): Event<void>;139140/**141* Get or create a browser view instance142* @param id The browser view identifier143* @param scope The storage scope for the browser view. Ignored if the view already exists.144* @param workspaceId Workspace identifier for session isolation. Only used if scope is 'workspace'.145*/146getOrCreateBrowserView(id: string, scope: BrowserViewStorageScope, workspaceId?: string): Promise<IBrowserViewState>;147148/**149* Destroy a browser view instance150* @param id The browser view identifier151*/152destroyBrowserView(id: string): Promise<void>;153154/**155* Update the bounds of a browser view156* @param id The browser view identifier157* @param bounds The new bounds for the view158*/159layout(id: string, bounds: IBrowserViewBounds): Promise<void>;160161/**162* Set the visibility of a browser view163* @param id The browser view identifier164* @param visible Whether the view should be visible165*/166setVisible(id: string, visible: boolean): Promise<void>;167168/**169* Navigate the browser view to a URL170* @param id The browser view identifier171* @param url The URL to navigate to172*/173loadURL(id: string, url: string): Promise<void>;174175/**176* Get the current URL of a browser view177* @param id The browser view identifier178*/179getURL(id: string): Promise<string>;180181/**182* Go back in navigation history183* @param id The browser view identifier184*/185goBack(id: string): Promise<void>;186187/**188* Go forward in navigation history189* @param id The browser view identifier190*/191goForward(id: string): Promise<void>;192193/**194* Reload the current page195* @param id The browser view identifier196*/197reload(id: string): Promise<void>;198199/**200* Toggle developer tools for the browser view.201* @param id The browser view identifier202*/203toggleDevTools(id: string): Promise<void>;204205/**206* Check if the view can go back207* @param id The browser view identifier208*/209canGoBack(id: string): Promise<boolean>;210211/**212* Check if the view can go forward213* @param id The browser view identifier214*/215canGoForward(id: string): Promise<boolean>;216217/**218* Capture a screenshot of the browser view219* @param id The browser view identifier220* @param options Screenshot options (quality and rect)221* @returns Screenshot as a buffer222*/223captureScreenshot(id: string, options?: IBrowserViewCaptureScreenshotOptions): Promise<VSBuffer>;224225/**226* Dispatch a key event to the browser view227* @param id The browser view identifier228* @param keyEvent The key event data229*/230dispatchKeyEvent(id: string, keyEvent: IBrowserViewKeyDownEvent): Promise<void>;231232/**233* Focus the browser view234* @param id The browser view identifier235*/236focus(id: string): Promise<void>;237238/**239* Find text in the browser view's page240* @param id The browser view identifier241* @param text The text to search for242* @param options Find options (forward direction, find next)243*/244findInPage(id: string, text: string, options?: IBrowserViewFindInPageOptions): Promise<void>;245246/**247* Stop the find in page session248* @param id The browser view identifier249* @param keepSelection Whether to keep the current selection250*/251stopFindInPage(id: string, keepSelection?: boolean): Promise<void>;252253/**254* Get the currently selected text in the browser view.255* Returns immediately with empty string if the page is still loading.256* @param id The browser view identifier257* @returns The selected text, or empty string if no selection or page is loading258*/259getSelectedText(id: string): Promise<string>;260261/**262* Clear all storage data for the global browser session263*/264clearGlobalStorage(): Promise<void>;265266/**267* Clear all storage data for a specific workspace browser session268* @param workspaceId The workspace identifier269*/270clearWorkspaceStorage(workspaceId: string): Promise<void>;271272/**273* Clear storage data for a specific browser view274* @param id The browser view identifier275*/276clearStorage(id: string): Promise<void>;277}278279280