/**
* @file
* This file is part of Adguard API MV3 library (https://github.com/AdguardTeam/tsurlfilter/packages/adguard-api-mv3).
*
* Adguard API MV3 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Adguard API MV3 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Adguard API MV3. If not, see .
*/
import { type LocalScriptFunctionData, type MessageHandler, TsWebExtension } from '@adguard/tswebextension/mv3';
import { type Configuration } from './configuration';
import { RequestBlockingLogger } from './request-blocking-logger';
export type AdguardApiParams = {
/**
* Local script rules data in JS format needed for validate unsafe script
* rules when UserScripts permission is not granted.
*/
localScriptRulesJs?: LocalScriptFunctionData;
};
/**
* AdGuard API is filtering library, provided following features:
* - request and content filtering, using {@link TsWebExtension}
* - content blocking via AdGuard Assistant UI, provided by {@link TsWebExtension}.
*/
export declare class AdguardApi {
private readonly tswebextension;
private static readonly WEB_ACCESSIBLE_RESOURCES_PATH;
private static readonly DECLARATIVE_RULES_PATH;
private configuration;
/**
* {@link TsWebExtension} {@link EventChannel}, which fires event on assistant rule creation.
*/
onAssistantCreateRule: typeof this.tswebextension.onAssistantCreateRule;
/**
* API for adding and removing listeners for request blocking events.
*
*/
onRequestBlocked: RequestBlockingLogger;
/**
* Creates new AdguardApi instance.
* @param tswebextension Instance of {@link TsWebExtension}.
* @param params Optional {@link AdguardApiParams} for AdguardApi.
*/
constructor(tswebextension: TsWebExtension, params?: AdguardApiParams);
/**
* Returns a message handler that will listen to internal messages,
* for example, message for get computed css for content-script.
* @returns Message handler.
*/
getMessageHandler(): MessageHandler;
/**
* Initializes AdGuard with specified {@link Configuration} and starts it immediately.
*
* @param configuration Api {@link Configuration}.
*
* @throws Error if Adguard is not started.
*
* @returns Applied {@link Configuration} promise.
*/
start(configuration: Configuration): Promise;
/**
* Completely stops AdGuard.
*/
stop(): Promise;
/**
* Modifies AdGuard {@link Configuration}. Please note, that Adguard must be already started.
*
* @param configuration Api {@link Configuration}.
*
* @throws Error if Adguard is not started.
*
* @returns Applied {@link Configuration} promise.
*/
configure(configuration: Configuration): Promise;
/**
* Opens the AdGuard assistant UI in the specified tab.
* You should also subscribe on {@link onAssistantCreateRule} event channel for applying rules,
* which are created by the Adguard assistant.
*
* @param tabId - {@link browser.tabs.Tab } id. @see https://developer.chrome.com/docs/extensions/reference/tabs/#type-Tab.
*/
openAssistant(tabId: number): Promise;
/**
* Closes AdGuard assistant in the specified tab.
*
* @param tabId - {@link browser.tabs.Tab } id. @see https://developer.chrome.com/docs/extensions/reference/tabs/#type-Tab.
*/
closeAssistant(tabId: number): Promise;
/**
* Gets current loaded rules count.
*
* @returns Rules count number.
*/
getRulesCount(): number;
/**
* Creates {@link TsWebExtension} configuration based on current API {@link configuration}.
*
* @returns - {@link TsWebExtension} configuration.
*/
private createTsWebExtensionConfiguration;
/**
* Creates new adguardApi instance.
*
* @param params Optional {@link AdguardApiParams} for AdguardApi.
*
* @returns AdguardApi instance.
*/
static create(params?: AdguardApiParams): Promise;
}