Skip to content

WebView API ​

The webview namespace provides diagnostic inspection of the calling WebView2 instance. Lifecycle events, such as webview:processFailed, are listed in Events API.

webview ​

webview.getSource ​

Report where the host loaded the calling WebView's page from: the development server, a URL, a template folder, or the built-in "Frontend not found" page. The host records this when it submits the navigation; a page that later navigates elsewhere by itself is still reported by that record. Fails with NOT_FOUND when the caller is not a WebView of this plugin or the host has not loaded a page into it.

This method takes no parameters.

Returns

FieldTypeDescription
source"devServer" | "url" | "panelTemplate" | "activeTemplate" | "componentDirectory" | "defaultTemplate" | "builtInPage"Where the page came from. devServer: the development server. url: a URL from the panel's configuration, or an absolute URL passed to window.createPopup. panelTemplate: the panel's own template. activeTemplate: the global active template. componentDirectory: foo_ui_webview2_resources\dist in the component's folder. defaultTemplate: webview-ui\default, reached because the folders before it had no index.html. builtInPage: the page shown when no folder had an index.html.
directorystringFolder mapped to https://foo-ui-webview2.local/; present for the four folder sources.
templateNamestringName of the template folder that was loaded; present for panelTemplate, activeTemplate and defaultTemplate.
urlstringAddress the host navigated to; present for devServer and url.
activeTemplateNamestringThe global active template as configured now, which can differ from the one loaded.
templatesDirectorystringFolder that holds the templates, webview-ui under the foobar2000 profile.

success is true on success. On failure the response is { success: false, error, code }; see Error codes for code.

The result describes the page as originally loaded by the host. activeTemplateName is read at the time of the call: for a page loaded from the active template, comparing it with templateName shows whether the user has picked another template since.

js
const source = await fb2k.invoke('webview.getSource');
if (source.success === false) throw new Error(source.error);
if (source.directory) {
	console.log(`Loaded ${source.templateName ?? 'a page'} from ${source.directory}`);
}