import { ContainerView, EventData, Property } from '@nativescript/core'; export interface ViewPortProperties { width?: number | 'device-width'; height?: number | 'device-height'; initialScale?: number; maximumScale?: number; minimumScale?: number; userScalable?: boolean; } export declare const WebViewTraceCategory = "AWebView"; export type CacheMode = 'default' | 'cache_first' | 'no_cache' | 'cache_only' | 'normal'; export declare const autoInjectJSBridgeProperty: Property; export declare const builtInZoomControlsProperty: Property; export declare const cacheModeProperty: Property; export declare const databaseStorageProperty: Property; export declare const domStorageProperty: Property; export declare const debugModeProperty: Property; export declare const webConsoleProperty: Property; export declare const displayZoomControlsProperty: Property; export declare const supportZoomProperty: Property; export declare const mediaPlaybackRequiresUserActionProperty: Property; export declare const allowsInlineMediaPlaybackProperty: Property; export declare const srcProperty: Property; export declare const scrollBounceProperty: Property; export declare const scalesPageToFitProperty: Property; export declare const isScrollEnabledProperty: Property; export declare const limitsNavigationsToAppBoundDomainsProperty: Property; export declare const scrollBarIndicatorVisibleProperty: Property; export declare const useWideViewPortProperty: Property; export declare const customUserAgentProperty: Property; export type ViewPortValue = boolean | ViewPortProperties; export declare const viewPortProperty: Property; export declare enum EventNames { LoadFinished = "loadFinished", LoadProgress = "loadProgress", LoadStarted = "loadStarted", ShouldOverrideUrlLoading = "shouldOverrideUrlLoading", TitleChanged = "titleChanged", WebAlert = "webAlert", WebConfirm = "webConfirm", WebConsole = "webConsole", EnterFullscreen = "enterFullscreen", ExitFullscreen = "exitFullscreen", WebPrompt = "webPrompt", RequestPermissions = "requestPermissions" } export interface LoadJavaScriptResource { resourceName: string; filepath: string; } export interface LoadStyleSheetResource { resourceName: string; filepath: string; insertBefore?: boolean; } export interface InjectExecuteJavaScript { scriptCode: string; name: string; } export interface WebViewExtEventData extends EventData { object: WebViewExtBase; } /** * Event data containing information for the loading events of a WebView. */ export interface LoadEventData extends WebViewExtEventData { /** * Gets the url of the web-view. */ url: string; /** * Gets the navigation type of the web-view. */ navigationType?: NavigationType; /** * Gets the error (if any). */ error?: string; } export interface LoadStartedEventData extends LoadEventData { eventName: EventNames.LoadStarted; } export interface LoadFinishedEventData extends LoadEventData { eventName: EventNames.LoadFinished; } export interface ShouldOverrideUrlLoadEventData extends LoadEventData { eventName: EventNames.ShouldOverrideUrlLoading; httpMethod: string; /** Flip this to true in your callback, if you want to cancel the url-loading */ cancel?: boolean; } /** BackForward compat for spelling error... */ export interface ShouldOverideUrlLoadEventData extends ShouldOverrideUrlLoadEventData { } export interface LoadProgressEventData extends WebViewExtEventData { eventName: EventNames.LoadProgress; url: string; progress: number; } export interface TitleChangedEventData extends WebViewExtEventData { eventName: EventNames.TitleChanged; url: string; title: string; } export interface WebAlertEventData extends WebViewExtEventData { eventName: EventNames.WebAlert; url: string; message: string; callback: () => void; } export interface WebPromptEventData extends WebViewExtEventData { eventName: EventNames.WebPrompt; url: string; message: string; defaultText?: string; callback: (response?: string) => void; } export interface WebConfirmEventData extends WebViewExtEventData { eventName: EventNames.WebConfirm; url: string; message: string; callback: (response: boolean) => void; } export interface WebConsoleEventData extends WebViewExtEventData { eventName: EventNames.WebConsole; url: string; data: { lineNo: number; message: string; level: string; }; } export interface RequestPermissionsEventData extends WebViewExtEventData { eventName: EventNames.RequestPermissions; url: string; permissions: string[]; } /** * Event data containing information for the loading events of a WebView. */ export interface WebViewEventData extends WebViewExtEventData { data?: any; } export interface EnterFullscreenEventData extends WebViewExtEventData { eventName: EventNames.EnterFullscreen; url: string; exitFullscreen(): void; } export interface ExitFullscreenEventData extends WebViewExtEventData { eventName: EventNames.ExitFullscreen; url: string; } /** * Represents navigation type */ export type NavigationType = 'linkClicked' | 'formSubmitted' | 'backForward' | 'reload' | 'formResubmitted' | 'other' | void; export declare class UnsupportedSDKError extends Error { constructor(minSdk: number); } export declare abstract class WebViewExtBase extends ContainerView { /** * ANDROID: should the webview support nested scroll. Default to true * * Note: This can break some web views like maps pinch to zoom. */ nestedScrollView: boolean; webConsoleEnabled: boolean; static readonly supportXLocalScheme: boolean; /** * Is Fetch API supported? * * Note: Android's Native Fetch API needs to be replaced with the polyfill. */ static isFetchSupported: boolean; /** * Does this platform's WebView support promises? */ static isPromiseSupported: boolean; scrollBarIndicatorVisible: boolean; get interceptScheme(): string; /** * String value used when hooking to loadStarted event. */ static get loadStartedEvent(): EventNames; /** * String value used when hooking to loadFinished event. */ static get loadFinishedEvent(): EventNames; /** String value used when hooking to shouldOverrideUrlLoading event */ static get shouldOverrideUrlLoadingEvent(): EventNames; static get loadProgressEvent(): EventNames; static get titleChangedEvent(): EventNames; static get webAlertEvent(): EventNames; static get webConfirmEvent(): EventNames; static get webPromptEvent(): EventNames; static get webConsoleEvent(): EventNames; static get enterFullscreenEvent(): EventNames; static get exitFullscreenEvent(): EventNames; static get requestPermissionsEvent(): EventNames; readonly supportXLocalScheme: boolean; /** * Gets or sets the url, local file path or HTML string. */ src: string; /** * Auto Inject WebView JavaScript Bridge on load finished? Defaults to true. */ autoInjectJSBridge: boolean; /** * Android: Enable/disable debug-mode */ debugMode: boolean; /** * Android: Is the built-in zoom mechanisms being used */ builtInZoomControls: boolean; /** * Android: displays on-screen zoom controls when using the built-in zoom mechanisms */ displayZoomControls: boolean; /** * Android: Enable/Disabled database storage API. * Note: It affects all webviews in the process. */ databaseStorage: boolean; /** * Android: Enable/Disabled DOM Storage API. E.g localStorage */ domStorage: boolean; /** * Android: should the webview support zoom */ supportZoom: boolean; /** * iOS: Should the scrollView bounce? Defaults to true. */ scrollBounce: boolean; /** * Set viewport metadata for the webview. * Set to false to disable. * * **Note**: WkWebView defaults initial-scale=1.0. */ viewPortSize: ViewPortValue; cacheMode: 'default' | 'no_cache' | 'cache_first' | 'cache_only'; /** * List of js-files to be auto injected on load finished */ protected autoInjectScriptFiles: LoadJavaScriptResource[]; /** * List of css-files to be auto injected on load finished */ protected autoInjectStyleSheetFiles: LoadStyleSheetResource[]; /** * List of code blocks to be executed after JS-files and CSS-files have been loaded. */ protected autoInjectJavaScriptBlocks: InjectExecuteJavaScript[]; /** * Prevent this.src loading changes from the webview's onLoadFinished-event */ protected tempSuspendSrcLoading: boolean; /** * Whether to install promise polyfill */ injectPolyfills: boolean; /** * Whether to install event bridge */ injectBridge: boolean; /** * Callback for the loadFinished-event. Called from the native-webview */ _onLoadFinished(url: string, error?: string): Promise; /** * Callback for onLoadStarted-event from the native webview * * @param url URL being loaded * @param navigationType Type of navigation (iOS-only) */ _onLoadStarted(url: string, navigationType?: NavigationType): void; /** * Callback for should override url loading. * Called from the native-webview * * @param url * @param httpMethod GET, POST etc * @param navigationType Type of navigation (iOS-only) */ _onShouldOverrideUrlLoading(url: string, httpMethod: string, navigationType?: NavigationType): boolean; _loadProgress(progress: number): void; _titleChanged(title: string): void; _webAlert(message: string, callback: () => void): boolean; _webConfirm(message: string, callback: (response: boolean | null) => void): boolean; _webPrompt(message: string, defaultText: string, callback: (response: string | null) => void): boolean; _webConsole(message: string, lineNo: number, level: string): boolean; _onEnterFullscreen(exitFullscreen: () => void): boolean; _onExitFullscreen(): boolean; /** * Platform specific loadURL-implementation. */ abstract _loadUrl(src: string): void; /** * Platform specific loadData-implementation. */ abstract _loadData(src: string): void; /** * Stops loading the current content (if any). */ abstract stopLoading(): any; /** * Gets a value indicating whether the WebView can navigate back. */ abstract get canGoBack(): boolean; /** * Gets a value indicating whether the WebView can navigate forward. */ abstract get canGoForward(): boolean; /** * Navigates back. */ abstract goBack(): any; /** * Navigates forward. */ abstract goForward(): any; /** * Reloads the current url. */ abstract reload(): any; resolveLocalResourceFilePath(filepath: string): string | void; /** * Register a local resource. * This resource can be loaded via "x-local://{name}" inside the webview */ abstract registerLocalResource(name: string, filepath: string): void; /** * Unregister a local resource. */ abstract unregisterLocalResource(name: string): void; /** * Resolve a "x-local://{name}" to file-path. */ abstract getRegisteredLocalResource(name: string): string | void; /** * Load URL - Wait for promise * * @param {string} src * @returns {Promise} */ loadUrl(src: string): Promise; /** * Load a JavaScript file on the current page in the webview. */ loadJavaScriptFile(scriptName: string, filepath: string): Promise; /** * Load multiple JavaScript-files on the current page in the webview. */ loadJavaScriptFiles(files: LoadStyleSheetResource[]): Promise; /** * Load a stylesheet file on the current page in the webview. */ loadStyleSheetFile(stylesheetName: string, filepath: string, insertBefore?: boolean): Promise; /** * Load multiple stylesheet-files on the current page in the webview */ loadStyleSheetFiles(files: LoadStyleSheetResource[]): Promise; /** * Auto-load a JavaScript-file after the page have been loaded. */ autoLoadJavaScriptFile(resourceName: string, filepath: string): void; removeAutoLoadJavaScriptFile(resourceName: string): void; /** * Auto-load a stylesheet-file after the page have been loaded. */ autoLoadStyleSheetFile(resourceName: string, filepath: string, insertBefore?: boolean): void; removeAutoLoadStyleSheetFile(resourceName: string): void; autoExecuteJavaScript(scriptCode: string, name: string): void; removeAutoExecuteJavaScript(name: string): void; /** * Ensure fetch-api is available. */ /** * Older Android WebView don't support promises. * Inject the promise-polyfill if needed. */ /** * Execute JavaScript inside the webview. * The code should be wrapped inside an anonymous-function. * Larger scripts should be injected with loadJavaScriptFile. * NOTE: stringifyResult only applies on iOS. */ abstract executeJavaScript(scriptCode: string, stringifyResult?: boolean): Promise; /** * Execute a promise inside the webview and wait for it to resolve. * Note: The scriptCode must return a promise. */ executePromise(scriptCode: string, timeout?: number): Promise; executePromises(scriptCodes: string[], timeout?: number): Promise; /** * Generate script code for loading javascript-file. */ generateLoadJavaScriptFileScriptCode(resourceName: string, path: string): Promise; /** * Generate script code for loading CSS-file.generateLoadCSSFileScriptCode */ generateLoadCSSFileScriptCode(resourceName: string, path: string, insertBefore?: boolean): Promise; /** * Inject WebView JavaScript Bridge. */ protected injectWebViewBridge(): Promise; protected injectViewPortMeta(): Promise; generateViewPortCode(): Promise; /** * Convert response from WebView into usable JS-type. */ protected parseWebViewJavascriptResult(result: any): any; writeTrace(message: string, type?: number): void; /** * Emit event into the webview. */ emitToWebView(eventName: string, data: any): void; /** * Called from delegate on webview event. * Triggered by: window.nsWebViewBridge.emit(eventName: string, data: any); inside the webview */ onWebViewEvent(eventName: string, data: any): void; /** * Get document.title * NOTE: On Android, if empty returns filename */ abstract getTitle(): Promise; abstract zoomIn(): boolean; abstract zoomOut(): boolean; abstract zoomBy(zoomFactor: number): any; /** * Helper function, strips 'x-local://' from a resource name */ fixLocalResourceName(resourceName: string): string; _onRequestPermissions(permissions: any): Promise; } export interface WebViewExtBase { /** * A basic method signature to hook an event listener (shortcut alias to the addEventListener method). * @param eventNames - String corresponding to events (e.g. "propertyChange"). Optionally could be used more events separated by `,` (e.g. "propertyChange", "change"). * @param callback - Callback function which will be executed when event is raised. * @param thisArg - An optional parameter which will be used as `this` context for callback execution. */ on(eventNames: string, callback: (data: WebViewEventData) => void, thisArg?: any): any; once(eventNames: string, callback: (data: WebViewEventData) => void, thisArg?: any): any; /** * Raised before the webview requests an URL. * Can be cancelled by settings args.cancel = true in your event handler. */ on(event: EventNames.ShouldOverrideUrlLoading, callback: (args: ShouldOverrideUrlLoadEventData) => void, thisArg?: any): any; once(event: EventNames.ShouldOverrideUrlLoading, callback: (args: ShouldOverrideUrlLoadEventData) => void, thisArg?: any): any; /** * Raised when a loadStarted event occurs. */ on(event: EventNames.LoadStarted, callback: (args: LoadStartedEventData) => void, thisArg?: any): any; once(event: EventNames.LoadStarted, callback: (args: LoadStartedEventData) => void, thisArg?: any): any; /** * Raised when a loadFinished event occurs. */ on(event: EventNames.LoadFinished, callback: (args: LoadFinishedEventData) => void, thisArg?: any): any; once(event: EventNames.LoadFinished, callback: (args: LoadFinishedEventData) => void, thisArg?: any): any; /** * Raised when a loadProgress event occurs. */ on(event: EventNames.LoadProgress, callback: (args: LoadProgressEventData) => void, thisArg?: any): any; once(event: EventNames.LoadProgress, callback: (args: LoadProgressEventData) => void, thisArg?: any): any; /** * Raised when a titleChanged event occurs. */ on(event: EventNames.TitleChanged, callback: (args: TitleChangedEventData) => void, thisArg?: any): any; once(event: EventNames.TitleChanged, callback: (args: TitleChangedEventData) => void, thisArg?: any): any; /** * Override web alerts to replace them. * Call args.cancel() on close. */ on(event: EventNames.WebAlert, callback: (args: WebAlertEventData) => void, thisArg?: any): any; once(event: EventNames.WebAlert, callback: (args: WebAlertEventData) => void, thisArg?: any): any; /** * Override web confirm dialogs to replace them. * Call args.cancel(res) on close. */ on(event: EventNames.WebConfirm, callback: (args: WebConfirmEventData) => void, thisArg?: any): any; once(event: EventNames.WebConfirm, callback: (args: WebConfirmEventData) => void, thisArg?: any): any; /** * Override web confirm prompts to replace them. * Call args.cancel(res) on close. */ on(event: EventNames.WebPrompt, callback: (args: WebPromptEventData) => void, thisArg?: any): any; once(event: EventNames.WebPrompt, callback: (args: WebPromptEventData) => void, thisArg?: any): any; /** * Get Android WebView console entries. */ on(event: EventNames.WebConsole, callback: (args: WebConsoleEventData) => void, thisArg?: any): any; once(event: EventNames.WebConsole, callback: (args: WebConsoleEventData) => void, thisArg?: any): any; /** * Get Android WebView console entries. */ on(event: EventNames.RequestPermissions, callback: (args: WebConsoleEventData) => void, thisArg?: any): any; once(event: EventNames.RequestPermissions, callback: (args: WebConsoleEventData) => void, thisArg?: any): any; }