Emoji favicons for the web
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add chrome type def

+1406 -91
+22 -28
source/background.ts
··· 2 2 * Serves as bridge point between popup and content_script. 3 3 */ 4 4 5 - import type { Settings, Tab } from './types.ts'; 5 + import type { Settings } from './types.ts'; 6 + import type { 7 + Tab, 8 + TabChangeInfo, 9 + } from './utilities/browser_api_interface/mod.ts'; 6 10 import { defaultSettings, STORAGE_KEYS } from './types.ts'; 7 11 import Autoselector from './utilities/autoselector.ts'; 8 12 import browserAPI from './utilities/browser_api.ts'; 9 13 10 - // https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/onUpdated 11 - interface Options { 12 - urls: string[]; 13 - properties: string[]; 14 - tabId: number; 15 - windowId: number; 16 - } 17 - 18 14 const autoselector = new Autoselector(); 19 - 20 - browserAPI.storage.sync.get( 21 - STORAGE_KEYS, 22 - (settings: Settings = defaultSettings) => { 23 - const { siteList = [], features = {} } = settings || defaultSettings; 15 + const settings: Settings = 16 + (await browserAPI.storage.sync.get(STORAGE_KEYS) as Settings | void) || 17 + defaultSettings; 24 18 25 - browserAPI.tabs.onUpdated.addListener( 26 - (tabId: string, _: Options, tab: Tab) => { 27 - if (!tab.url) return; 19 + const { siteList = [], features = {} } = settings || defaultSettings; 28 20 29 - const shouldOverride = (siteList || []).some( 30 - (site: string) => (new RegExp(site)).test(tab.url || ''), 31 - ); 21 + browserAPI.tabs.onUpdated.addListener( 22 + (tabId: number, _: TabChangeInfo, tab: Tab) => { 23 + if (!tab.url) return; 32 24 33 - if (shouldOverride) { 34 - const favicon = { id: 'smile', emoji: '😀' }; 35 - browserAPI.tabs.sendMessage(tabId, { favicon, shouldOverride: true }); 36 - } else if (features.enableFaviconAutofill) { 37 - const favicon = autoselector.selectFavicon(new URL(tab.url).host); 38 - browserAPI.tabs.sendMessage(tabId, { favicon, shouldOverride }); 39 - } 40 - }, 25 + const shouldOverride = (siteList || []).some( 26 + (site: string) => (new RegExp(site)).test(tab.url || ''), 41 27 ); 28 + 29 + if (shouldOverride) { 30 + const favicon = { id: 'smile', emoji: '😀' }; 31 + browserAPI.tabs.sendMessage(tabId, { favicon, shouldOverride: true }); 32 + } else if (features.enableFaviconAutofill) { 33 + const favicon = autoselector.selectFavicon(new URL(tab.url).host); 34 + browserAPI.tabs.sendMessage(tabId, { favicon, shouldOverride }); 35 + } 42 36 }, 43 37 );
+15 -13
source/hooks/use_browser_storage.ts
··· 35 35 const [loading, setLoading] = useState<boolean>(true); 36 36 37 37 useEffect(() => { 38 - storage.sync.get(keys, (result: Type) => { 39 - if (runtime.lastError) setError(runtime.lastError); 40 - setCache(result); 41 - setLoading(false); 42 - }); 38 + storage.sync.get(keys) 39 + .then((storage) => { 40 + if (runtime?.lastError?.message) setError(runtime?.lastError?.message); 41 + setCache(storage as Type); 42 + setLoading(false); 43 + }); 43 44 }, []); 44 45 45 46 const result: BrowserStorage<Type> = { ··· 75 76 if (!hasPermission) return Promise.reject('No Permission Given'); 76 77 77 78 return new Promise((resolve, reject) => 78 - storage.sync.set(nextStorage, () => { 79 - if (runtime.lastError) { 80 - setError(runtime.lastError); 81 - reject(runtime.lastError); 82 - } else { 83 - resolve(); 84 - } 85 - }) 79 + storage.sync.set(nextStorage) 80 + .then(() => { 81 + if (runtime?.lastError?.message) { 82 + setError(runtime?.lastError?.message); 83 + reject(runtime?.lastError?.message); 84 + } else { 85 + resolve(); 86 + } 87 + }) 86 88 ); 87 89 }, 88 90 };
+9 -49
source/utilities/browser_api.ts
··· 1 + // deno-lint-ignore-file 2 + 1 3 /** 2 4 * API for more platform-agnostic access to browser extension apis. 3 5 * Since browers ext API is kind of shifting sands, let's not do too much ··· 8 10 * @reference https://developer.chrome.com/docs/extensions/reference 9 11 * @reference https://docs.microsoft.com/en-us/microsoft-edge/extensions-chromium/developer-guide/api-support 10 12 * 11 - * @todo figure out how to properly import/declare/export global type from definitelyTyped. 12 - * Also looks like definitelyTyped is only for "chrome" global, so would need to map to 13 - * "browser" for approx. firefox types. 13 + * @todo Borrows heavily from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/chrome 14 14 */ 15 + import { isChrome } from './predicates.ts'; 16 + import { BrowserAPI } from './browser_api_interface/mod.ts'; 15 17 16 - export type BrowserName = 'CHROME' | 'FIREFOX'; 17 - 18 - interface BrowserExtensionAPI { 19 - // See @todo: 18 + const browserAPI: BrowserAPI = isChrome() 20 19 // deno-lint-ignore no-explicit-any 21 - [name: string]: any; 22 - } 23 - 24 - declare global { 25 - const browser: BrowserExtensionAPI; 26 - const chrome: BrowserExtensionAPI; 27 - } 28 - 29 - const CHROME = 'CHROME'; 30 - const FIREFOX = 'FIREFOX'; 31 - const browserAPI = isBrowser(CHROME) ? chrome : browser; // Default to Chromium 20 + ? (globalThis as any).chrome 21 + : // deno-lint-ignore no-explicit-any 22 + (globalThis as any).browser; 32 23 33 24 export default browserAPI; 34 - 35 - /** 36 - * What browser is this? 37 - * @param {string} toCheck to check 38 - */ 39 - export function isBrowser(toCheck: BrowserName): boolean { 40 - let currentBrowser = CHROME; 41 - try { 42 - // Use try block, since userAgent not guaranteed to exist. 43 - // If fail, assume Chromium 44 - // deno-lint-ignore no-explicit-any 45 - const userAgent: string = (navigator as any)?.userAgent || ''; 46 - if (userAgent.indexOf('Firefox') > 0) { 47 - currentBrowser = FIREFOX; 48 - } 49 - } catch (_) { 50 - // Do nothing 51 - } 52 - 53 - if (!toCheck) currentBrowser; 54 - if (toCheck === CHROME && currentBrowser === CHROME) return true; 55 - if (toCheck === FIREFOX && currentBrowser === FIREFOX) return true; 56 - return false; 57 - } 58 - 59 - export function isChrome(): boolean { 60 - return isBrowser(CHROME); 61 - } 62 - export function isFirefox(): boolean { 63 - return isBrowser(FIREFOX); 64 - }
+13
source/utilities/browser_api_interface/mod.ts
··· 1 + import type { PermissionsModule } from './modules/permissions.ts'; 2 + import type { RuntimeModule } from './modules/runtime.ts'; 3 + import type { StorageModule } from './modules/storage.ts'; 4 + import type { TabsModule } from './modules/tabs.ts'; 5 + 6 + export * from './modules/tabs.ts'; 7 + 8 + export interface BrowserAPI { 9 + permissions: PermissionsModule; 10 + runtime: RuntimeModule; 11 + storage: StorageModule; 12 + tabs: TabsModule; 13 + }
+56
source/utilities/browser_api_interface/modules/event.ts
··· 1 + // deno-lint-ignore-file no-explicit-any 2 + 3 + import type { RequestFilter } from './web_request.ts'; 4 + 5 + export type Function = (...args: any[]) => any | void; 6 + 7 + export interface UrlFilter { 8 + schemes?: string[] | undefined; 9 + urlMatches?: string | undefined; 10 + pathContains?: string | undefined; 11 + hostSuffix?: string | undefined; 12 + hostPrefix?: string | undefined; 13 + hostContains?: string | undefined; 14 + urlContains?: string | undefined; 15 + querySuffix?: string | undefined; 16 + urlPrefix?: string | undefined; 17 + hostEquals?: string | undefined; 18 + urlEquals?: string | undefined; 19 + queryContains?: string | undefined; 20 + pathPrefix?: string | undefined; 21 + pathEquals?: string | undefined; 22 + pathSuffix?: string | undefined; 23 + queryEquals?: string | undefined; 24 + queryPrefix?: string | undefined; 25 + urlSuffix?: string | undefined; 26 + ports?: (number | number[])[] | undefined; 27 + originAndPathMatches?: string | undefined; 28 + } 29 + 30 + export interface BaseEvent<T extends Function> { 31 + addListener(callback: T, filter?: RequestFilter): void; 32 + getRules(callback: (rules: Rule[]) => void): void; 33 + getRules(ruleIdentifiers: string[], callback: (rules: Rule[]) => void): void; 34 + hasListener(callback: T): boolean; 35 + removeRules(ruleIdentifiers?: string[], callback?: () => void): void; 36 + removeRules(callback?: () => void): void; 37 + addRules(rules: Rule[], callback?: (rules: Rule[]) => void): void; 38 + removeListener(callback: T): void; 39 + hasListeners(): boolean; 40 + } 41 + 42 + export interface Event<T extends Function> extends BaseEvent<T> { 43 + addListener(callback: T): void; 44 + } 45 + export interface EventWithRequiredFilterInAddListener<T extends Function> 46 + extends BaseEvent<T> { 47 + addListener(callback: T, filter: RequestFilter): void; 48 + } 49 + 50 + export interface Rule { 51 + priority?: number | undefined; 52 + conditions: any[]; 53 + id?: string | undefined; 54 + actions: any[]; 55 + tags?: string[] | undefined; 56 + }
+340
source/utilities/browser_api_interface/modules/manifest.ts
··· 1 + // deno-lint-ignore-file no-explicit-any 2 + 3 + export interface PageStateUrlDetails { 4 + hostContains?: string | undefined; 5 + hostEquals?: string | undefined; 6 + hostPrefix?: string | undefined; 7 + hostSuffix?: string | undefined; 8 + pathContains?: string | undefined; 9 + pathEquals?: string | undefined; 10 + pathPrefix?: string | undefined; 11 + pathSuffix?: string | undefined; 12 + queryContains?: string | undefined; 13 + queryEquals?: string | undefined; 14 + queryPrefix?: string | undefined; 15 + querySuffix?: string | undefined; 16 + urlContains?: string | undefined; 17 + urlEquals?: string | undefined; 18 + urlMatches?: string | undefined; 19 + originAndPathMatches?: string | undefined; 20 + urlPrefix?: string | undefined; 21 + urlSuffix?: string | undefined; 22 + schemes?: string[] | undefined; 23 + ports?: (number | number[])[] | undefined; 24 + } 25 + 26 + export class PageStateMatcherProperties { 27 + pageUrl?: PageStateUrlDetails | undefined; 28 + css?: string[] | undefined; 29 + isBookmarked?: boolean | undefined; 30 + } 31 + 32 + export interface SearchProvider { 33 + name?: string | undefined; 34 + keyword?: string | undefined; 35 + favicon_url?: string | undefined; 36 + search_url: string; 37 + encoding?: string | undefined; 38 + suggest_url?: string | undefined; 39 + instant_url?: string | undefined; 40 + image_url?: string | undefined; 41 + search_url_post_params?: string | undefined; 42 + suggest_url_post_params?: string | undefined; 43 + instant_url_post_params?: string | undefined; 44 + image_url_post_params?: string | undefined; 45 + alternate_urls?: string[] | undefined; 46 + prepopulated_id?: number | undefined; 47 + is_default?: boolean | undefined; 48 + } 49 + 50 + export interface ManifestIcons { 51 + [size: number]: string; 52 + } 53 + 54 + export interface ManifestAction { 55 + default_icon?: ManifestIcons | undefined; 56 + default_title?: string | undefined; 57 + default_popup?: string | undefined; 58 + } 59 + 60 + // Source: https://developer.chrome.com/docs/extensions/mv3/declare_permissions/ 61 + export type ManifestPermissions = 62 + | 'activeTab' 63 + | 'alarms' 64 + | 'background' 65 + | 'bookmarks' 66 + | 'browsingData' 67 + | 'certificateProvider' 68 + | 'clipboardRead' 69 + | 'clipboardWrite' 70 + | 'contentSettings' 71 + | 'contextMenus' 72 + | 'cookies' 73 + | 'debugger' 74 + | 'declarativeContent' 75 + | 'declarativeNetRequest' 76 + | 'declarativeNetRequestFeedback' 77 + | 'declarativeWebRequest' 78 + | 'desktopCapture' 79 + | 'documentScan' 80 + | 'downloads' 81 + | 'enterprise.deviceAttributes' 82 + | 'enterprise.hardwarePlatform' 83 + | 'enterprise.networkingAttributes' 84 + | 'enterprise.platformKeys' 85 + | 'experimental' 86 + | 'fileBrowserHandler' 87 + | 'fileSystemProvider' 88 + | 'fontSettings' 89 + | 'gcm' 90 + | 'geolocation' 91 + | 'history' 92 + | 'identity' 93 + | 'idle' 94 + | 'loginState' 95 + | 'management' 96 + | 'nativeMessaging' 97 + | 'notifications' 98 + | 'pageCapture' 99 + | 'platformKeys' 100 + | 'power' 101 + | 'printerProvider' 102 + | 'printing' 103 + | 'printingMetrics' 104 + | 'privacy' 105 + | 'processes' 106 + | 'proxy' 107 + | 'scripting' 108 + | 'search' 109 + | 'sessions' 110 + | 'signedInDevices' 111 + | 'storage' 112 + | 'system.cpu' 113 + | 'system.display' 114 + | 'system.memory' 115 + | 'system.storage' 116 + | 'tabCapture' 117 + | 'tabGroups' 118 + | 'tabs' 119 + | 'topSites' 120 + | 'tts' 121 + | 'ttsEngine' 122 + | 'unlimitedStorage' 123 + | 'vpnProvider' 124 + | 'wallpaper' 125 + | 'webNavigation' 126 + | 'webRequest' 127 + | 'webRequestBlocking'; 128 + 129 + export interface ManifestBase { 130 + // Required 131 + manifest_version: number; 132 + name: string; 133 + version: string; 134 + 135 + // Recommended 136 + default_locale?: string | undefined; 137 + description?: string | undefined; 138 + icons?: ManifestIcons | undefined; 139 + 140 + // Optional 141 + author?: string | undefined; 142 + background_page?: string | undefined; 143 + chrome_settings_overrides?: { 144 + homepage?: string | undefined; 145 + search_provider?: SearchProvider | undefined; 146 + startup_pages?: string[] | undefined; 147 + } | undefined; 148 + chrome_ui_overrides?: { 149 + bookmarks_ui?: { 150 + remove_bookmark_shortcut?: boolean | undefined; 151 + remove_button?: boolean | undefined; 152 + } | undefined; 153 + } | undefined; 154 + chrome_url_overrides?: { 155 + bookmarks?: string | undefined; 156 + history?: string | undefined; 157 + newtab?: string | undefined; 158 + } | undefined; 159 + commands?: { 160 + [name: string]: { 161 + suggested_key?: { 162 + default?: string | undefined; 163 + windows?: string | undefined; 164 + mac?: string | undefined; 165 + chromeos?: string | undefined; 166 + linux?: string | undefined; 167 + } | undefined; 168 + description?: string | undefined; 169 + global?: boolean | undefined; 170 + }; 171 + } | undefined; 172 + content_capabilities?: { 173 + matches?: string[] | undefined; 174 + permissions?: string[] | undefined; 175 + } | undefined; 176 + content_scripts?: { 177 + matches?: string[] | undefined; 178 + exclude_matches?: string[] | undefined; 179 + css?: string[] | undefined; 180 + js?: string[] | undefined; 181 + run_at?: string | undefined; 182 + all_frames?: boolean | undefined; 183 + match_about_blank?: boolean | undefined; 184 + include_globs?: string[] | undefined; 185 + exclude_globs?: string[] | undefined; 186 + }[] | undefined; 187 + converted_from_user_script?: boolean | undefined; 188 + current_locale?: string | undefined; 189 + devtools_page?: string | undefined; 190 + event_rules?: { 191 + event?: string | undefined; 192 + actions?: { 193 + type: string; 194 + }[] | undefined; 195 + conditions?: 196 + | PageStateMatcherProperties[] 197 + | undefined; 198 + }[] | undefined; 199 + externally_connectable?: { 200 + ids?: string[] | undefined; 201 + matches?: string[] | undefined; 202 + accepts_tls_channel_id?: boolean | undefined; 203 + } | undefined; 204 + file_browser_handlers?: { 205 + id?: string | undefined; 206 + default_title?: string | undefined; 207 + file_filters?: string[] | undefined; 208 + }[] | undefined; 209 + file_system_provider_capabilities?: { 210 + configurable?: boolean | undefined; 211 + watchable?: boolean | undefined; 212 + multiple_mounts?: boolean | undefined; 213 + source?: string | undefined; 214 + } | undefined; 215 + homepage_url?: string | undefined; 216 + import?: { 217 + id: string; 218 + minimum_version?: string | undefined; 219 + }[] | undefined; 220 + export?: { 221 + whitelist?: string[] | undefined; 222 + } | undefined; 223 + incognito?: string | undefined; 224 + input_components?: { 225 + name?: string | undefined; 226 + type?: string | undefined; 227 + id?: string | undefined; 228 + description?: string | undefined; 229 + language?: string | undefined; 230 + layouts?: string[] | undefined; 231 + }[] | undefined; 232 + key?: string | undefined; 233 + minimum_chrome_version?: string | undefined; 234 + nacl_modules?: { 235 + path: string; 236 + mime_type: string; 237 + }[] | undefined; 238 + oauth2?: { 239 + client_id: string; 240 + scopes?: string[] | undefined; 241 + } | undefined; 242 + offline_enabled?: boolean | undefined; 243 + omnibox?: { 244 + keyword: string; 245 + } | undefined; 246 + options_page?: string | undefined; 247 + options_ui?: { 248 + page?: string | undefined; 249 + chrome_style?: boolean | undefined; 250 + open_in_tab?: boolean | undefined; 251 + } | undefined; 252 + platforms?: { 253 + nacl_arch?: string | undefined; 254 + sub_package_path: string; 255 + }[] | undefined; 256 + plugins?: { 257 + path: string; 258 + }[] | undefined; 259 + requirements?: { 260 + '3D'?: { 261 + features?: string[] | undefined; 262 + } | undefined; 263 + plugins?: { 264 + npapi?: boolean | undefined; 265 + } | undefined; 266 + } | undefined; 267 + sandbox?: { 268 + pages: string[]; 269 + content_security_policy?: string | undefined; 270 + } | undefined; 271 + short_name?: string | undefined; 272 + spellcheck?: { 273 + dictionary_language?: string | undefined; 274 + dictionary_locale?: string | undefined; 275 + dictionary_format?: string | undefined; 276 + dictionary_path?: string | undefined; 277 + } | undefined; 278 + storage?: { 279 + managed_schema: string; 280 + } | undefined; 281 + tts_engine?: { 282 + voices: { 283 + voice_name: string; 284 + lang?: string | undefined; 285 + gender?: string | undefined; 286 + event_types?: string[] | undefined; 287 + }[]; 288 + } | undefined; 289 + update_url?: string | undefined; 290 + version_name?: string | undefined; 291 + [key: string]: any; 292 + } 293 + 294 + export interface ManifestV2 extends ManifestBase { 295 + // Required 296 + manifest_version: 2; 297 + 298 + // Pick one (or none) 299 + browser_action?: ManifestAction | undefined; 300 + page_action?: ManifestAction | undefined; 301 + 302 + // Optional 303 + background?: 304 + | { 305 + scripts?: string[] | undefined; 306 + page?: string | undefined; 307 + persistent?: boolean | undefined; 308 + } 309 + | undefined; 310 + content_security_policy?: string | undefined; 311 + optional_permissions?: string[] | undefined; 312 + permissions?: string[] | undefined; 313 + web_accessible_resources?: string[] | undefined; 314 + } 315 + 316 + export interface ManifestV3 extends ManifestBase { 317 + // Required 318 + manifest_version: 3; 319 + 320 + // Optional 321 + action?: ManifestAction | undefined; 322 + background?: 323 + | { 324 + service_worker: string; 325 + type?: 'module'; // If the service worker uses ES modules 326 + } 327 + | undefined; 328 + content_security_policy?: { 329 + extension_pages?: string; 330 + sandbox?: string; 331 + }; 332 + host_permissions?: string[] | undefined; 333 + optional_permissions?: ManifestPermissions[] | undefined; 334 + permissions?: ManifestPermissions[] | undefined; 335 + web_accessible_resources?: 336 + | { resources: string[]; matches: string[] }[] 337 + | undefined; 338 + } 339 + 340 + export type Manifest = ManifestV2 | ManifestV3;
+26
source/utilities/browser_api_interface/modules/permissions.ts
··· 1 + interface Permissions { 2 + permissions?: string[]; 3 + origins?: string[]; 4 + } 5 + 6 + export interface PermissionsModule { 7 + contains: ( 8 + permissions: Permissions, 9 + callback: (result: boolean) => void, 10 + ) => void; 11 + request: ( 12 + permissions: Permissions, 13 + callback?: (granted: boolean) => void, 14 + ) => void; 15 + getAll: (callback: (permissions: Permissions) => void) => void; 16 + remove: ( 17 + permissions: Permissions, 18 + callback?: (removed: boolean) => void, 19 + ) => void; 20 + onRemoved: { 21 + addListener: (callback: (permissions: Permissions) => void) => void; 22 + }; 23 + onAdded: { 24 + addListener: (callback: (permissions: Permissions) => void) => void; 25 + }; 26 + }
+35
source/utilities/browser_api_interface/modules/platform.ts
··· 1 + /** https://developer.chrome.com/docs/extensions/reference/runtime/#type-PlatformOs */ 2 + export type PlatformOs = 3 + | 'mac' 4 + | 'win' 5 + | 'android' 6 + | 'cros' 7 + | 'linux' 8 + | 'openbsd'; 9 + 10 + /** https://developer.chrome.com/docs/extensions/reference/runtime/#type-PlatformArch */ 11 + export type PlatformArch = 12 + | 'arm' 13 + | 'arm64' 14 + | 'x86-32' 15 + | 'x86-64' 16 + | 'mips' 17 + | 'mips64'; 18 + 19 + /** https://developer.chrome.com/docs/extensions/reference/runtime/#type-PlatformNaclArch */ 20 + export type PlatformNaclArch = 'arm' | 'x86-32' | 'x86-64' | 'mips' | 'mips64'; 21 + 22 + export interface PlatformInfo { 23 + /** 24 + * The operating system chrome is running on. 25 + */ 26 + os: PlatformOs; 27 + /** 28 + * The machine's processor architecture. 29 + */ 30 + arch: PlatformArch; 31 + /** 32 + * The native client architecture. This may be different from arch on some platforms. 33 + */ 34 + nacl_arch: PlatformNaclArch; 35 + }
+141
source/utilities/browser_api_interface/modules/runtime.ts
··· 1 + // deno-lint-ignore-file no-explicit-any 2 + 3 + import type { Manifest } from './manifest.ts'; 4 + import type { PlatformInfo } from './platform.ts'; 5 + import type { Tab } from './tabs.ts'; 6 + import type { Event } from './event.ts'; 7 + 8 + interface Object { 9 + [name: string]: any; 10 + } 11 + 12 + /** https://developer.chrome.com/docs/extensions/reference/runtime/#type-OnInstalledReason */ 13 + export enum OnInstalledReason { 14 + INSTALL = 'install', 15 + UPDATE = 'update', 16 + CHROME_UPDATE = 'chrome_update', 17 + SHARED_MODULE_UPDATE = 'shared_module_update', 18 + } 19 + 20 + export interface LastError { 21 + message?: string | undefined; 22 + } 23 + 24 + export interface ConnectInfo { 25 + name?: string | undefined; 26 + includeTlsChannelId?: boolean | undefined; 27 + } 28 + 29 + export interface InstalledDetails { 30 + reason: OnInstalledReason; 31 + previousVersion?: string | undefined; 32 + id?: string | undefined; 33 + } 34 + 35 + export interface MessageOptions { 36 + /** Whether the TLS channel ID will be passed into onMessageExternal for processes that are listening for the connection event. */ 37 + includeTlsChannelId?: boolean | undefined; 38 + } 39 + 40 + export interface MessageSender { 41 + id?: string | undefined; 42 + tab?: Tab | undefined; 43 + nativeApplication?: string | undefined; 44 + frameId?: number | undefined; 45 + url?: string | undefined; 46 + tlsChannelId?: string | undefined; 47 + origin?: string | undefined; 48 + } 49 + 50 + export interface Port { 51 + postMessage: (message: any) => void; 52 + disconnect: () => void; 53 + sender?: MessageSender | undefined; 54 + onDisconnect: PortDisconnectEvent; 55 + onMessage: PortMessageEvent; 56 + name: string; 57 + } 58 + 59 + export interface UpdateAvailableDetails { 60 + version: string; 61 + } 62 + 63 + export interface UpdateCheckDetails { 64 + version: string; 65 + } 66 + 67 + export type RequestUpdateCheckStatus = 68 + | 'throttled' 69 + | 'no_update' 70 + | 'update_available'; 71 + 72 + export type PortDisconnectEvent = Event<(port: Port) => void>; 73 + 74 + export type PortMessageEvent = Event< 75 + (message: any, port: Port) => void 76 + >; 77 + 78 + export type ExtensionMessageEvent = Event< 79 + ( 80 + message: any, 81 + sender: MessageSender, 82 + sendResponse: (response?: any) => void, 83 + ) => void 84 + >; 85 + 86 + export type ExtensionConnectEvent = Event<(port: Port) => void>; 87 + export type RuntimeEvent = Event<() => void>; 88 + export type RuntimeRestartRequiredEvent = Event< 89 + (reason: string) => void 90 + >; 91 + export type RuntimeUpdateAvailableEvent = Event< 92 + (details: UpdateAvailableDetails) => void 93 + >; 94 + 95 + export interface RuntimeModule { 96 + lastError: LastError | undefined; 97 + id: string; 98 + 99 + onConnect: ExtensionConnectEvent; 100 + onConnectExternal: ExtensionConnectEvent; 101 + onSuspend: RuntimeEvent; 102 + onStartup: RuntimeEvent; 103 + onInstalled: RuntimeEvent; 104 + onSuspendCanceled: RuntimeEvent; 105 + onMessage: ExtensionMessageEvent; 106 + onMessageExternal: ExtensionMessageEvent; 107 + onRestartRequired: RuntimeRestartRequiredEvent; 108 + onUpdateAvailable: RuntimeUpdateAvailableEvent; 109 + onBrowserUpdateAvailable: RuntimeEvent; 110 + 111 + connect: (connectInfo?: ConnectInfo) => Port; 112 + connectNative: (application: string) => Port; 113 + getBackgroundPage: (callback: (backgroundPage?: Window) => void) => void; 114 + getManifest: () => Manifest; 115 + getPackageDirectoryEntry: ( 116 + callback: (directoryEntry: any) => void, 117 + ) => void; 118 + getPlatformInfo: () => Promise<PlatformInfo>; 119 + getURL: (path: string) => string; 120 + reload: () => void; 121 + requestUpdateCheck: ( 122 + callback: ( 123 + status: RequestUpdateCheckStatus, 124 + details?: UpdateCheckDetails, 125 + ) => void, 126 + ) => void; 127 + restart: () => void; 128 + restartAfterDelay: (seconds: number, callback?: () => void) => void; 129 + sendMessage: <M, R>( 130 + message: M, 131 + options: MessageOptions, 132 + responseCallback: (response: R) => void, 133 + ) => void; 134 + sendNativeMessage: ( 135 + application: string, 136 + message: Object, 137 + responseCallback: (response: any) => void, 138 + ) => void; 139 + setUninstallURL: (url: string, callback?: () => void) => void; 140 + openOptionsPage: (callback?: () => void) => void; 141 + }
+43
source/utilities/browser_api_interface/modules/storage.ts
··· 1 + // deno-lint-ignore-file no-explicit-any no-empty-interface 2 + import { Event } from './event.ts'; 3 + 4 + export interface StorageArea { 5 + getBytesInUse(keys?: string | string[] | null): Promise<number>; 6 + clear(): Promise<void>; 7 + set(items: { [key: string]: any }): Promise<void>; 8 + remove(keys: string | string[]): Promise<void>; 9 + get( 10 + keys?: string | string[] | { [key: string]: any } | null, 11 + ): Promise<{ [key: string]: any }>; 12 + } 13 + 14 + export interface StorageChange { 15 + newValue?: any; 16 + oldValue?: any; 17 + } 18 + 19 + export interface LocalStorageArea extends StorageArea { 20 + QUOTA_BYTES: number; 21 + } 22 + 23 + export interface SyncStorageArea extends StorageArea { 24 + MAX_SUSTAINED_WRITE_OPERATIONS_PER_MINUTE: number; 25 + QUOTA_BYTES: number; 26 + QUOTA_BYTES_PER_ITEM: number; 27 + MAX_ITEMS: number; 28 + MAX_WRITE_OPERATIONS_PER_HOUR: number; 29 + MAX_WRITE_OPERATIONS_PER_MINUTE: number; 30 + } 31 + 32 + type AreaName = 'sync' | 'local' | 'managed'; 33 + export interface StorageChangedEvent extends 34 + Event< 35 + (changes: { [key: string]: StorageChange }, areaName: AreaName) => void 36 + > {} 37 + 38 + export interface StorageModule { 39 + local: LocalStorageArea; 40 + sync: SyncStorageArea; 41 + managed: StorageArea; 42 + onChanged: StorageChangedEvent; 43 + }
+287
source/utilities/browser_api_interface/modules/tabs.ts
··· 1 + // deno-lint-ignore-file no-explicit-any 2 + 3 + import type { Window } from './windows.ts'; 4 + import type { Event } from './event.ts'; 5 + import type { Port } from './runtime.ts'; 6 + 7 + export interface MutedInfo { 8 + muted: boolean; 9 + reason?: string | undefined; 10 + extensionId?: string | undefined; 11 + } 12 + 13 + export interface Tab { 14 + status?: string | undefined; 15 + index: number; 16 + openerTabId?: number | undefined; 17 + title?: string | undefined; 18 + url?: string | undefined; 19 + pendingUrl?: string | undefined; 20 + pinned: boolean; 21 + highlighted: boolean; 22 + windowId: number; 23 + active: boolean; 24 + favIconUrl?: string | undefined; 25 + id?: number | undefined; 26 + incognito: boolean; 27 + selected: boolean; 28 + audible?: boolean | undefined; 29 + discarded: boolean; 30 + autoDiscardable: boolean; 31 + mutedInfo?: MutedInfo | undefined; 32 + width?: number | undefined; 33 + height?: number | undefined; 34 + sessionId?: string | undefined; 35 + groupId: number; 36 + } 37 + 38 + export interface ZoomSettings { 39 + mode?: string | undefined; 40 + scope?: string | undefined; 41 + defaultZoomFactor?: number | undefined; 42 + } 43 + 44 + export interface InjectDetails { 45 + allFrames?: boolean | undefined; 46 + code?: string | undefined; 47 + runAt?: string | undefined; 48 + file?: string | undefined; 49 + frameId?: number | undefined; 50 + matchAboutBlank?: boolean | undefined; 51 + cssOrigin?: string | undefined; 52 + } 53 + 54 + export interface CreateProperties { 55 + index?: number | undefined; 56 + openerTabId?: number | undefined; 57 + url?: string | undefined; 58 + pinned?: boolean | undefined; 59 + windowId?: number | undefined; 60 + active?: boolean | undefined; 61 + selected?: boolean | undefined; 62 + } 63 + 64 + export interface MoveProperties { 65 + index: number; 66 + windowId?: number | undefined; 67 + } 68 + 69 + export interface UpdateProperties { 70 + pinned?: boolean | undefined; 71 + openerTabId?: number | undefined; 72 + url?: string | undefined; 73 + highlighted?: boolean | undefined; 74 + active?: boolean | undefined; 75 + selected?: boolean | undefined; 76 + muted?: boolean | undefined; 77 + autoDiscardable?: boolean | undefined; 78 + } 79 + 80 + export interface CaptureVisibleTabOptions { 81 + quality?: number | undefined; 82 + format?: string | undefined; 83 + } 84 + 85 + export interface ReloadProperties { 86 + bypassCache?: boolean | undefined; 87 + } 88 + 89 + export interface ConnectInfo { 90 + name?: string | undefined; 91 + frameId?: number | undefined; 92 + } 93 + 94 + export interface MessageSendOptions { 95 + frameId?: number | undefined; 96 + } 97 + 98 + export interface GroupOptions { 99 + createProperties?: { 100 + windowId?: number | undefined; 101 + } | undefined; 102 + groupId?: number | undefined; 103 + tabIds?: number | number[] | undefined; 104 + } 105 + 106 + export interface HighlightInfo { 107 + tabs: number | number[]; 108 + windowId?: number | undefined; 109 + } 110 + 111 + export interface QueryInfo { 112 + status?: 'loading' | 'complete' | undefined; 113 + lastFocusedWindow?: boolean | undefined; 114 + windowId?: number | undefined; 115 + windowType?: 'normal' | 'popup' | 'panel' | 'app' | 'devtools' | undefined; 116 + active?: boolean | undefined; 117 + index?: number | undefined; 118 + title?: string | undefined; 119 + url?: string | string[] | undefined; 120 + currentWindow?: boolean | undefined; 121 + highlighted?: boolean | undefined; 122 + discarded?: boolean | undefined; 123 + autoDiscardable?: boolean | undefined; 124 + pinned?: boolean | undefined; 125 + audible?: boolean | undefined; 126 + muted?: boolean | undefined; 127 + groupId?: number | undefined; 128 + } 129 + 130 + export interface TabHighlightInfo { 131 + windowId: number; 132 + tabIds: number[]; 133 + } 134 + 135 + export interface TabRemoveInfo { 136 + windowId: number; 137 + isWindowClosing: boolean; 138 + } 139 + 140 + export interface TabAttachInfo { 141 + newPosition: number; 142 + newWindowId: number; 143 + } 144 + 145 + export interface TabChangeInfo { 146 + status?: string | undefined; 147 + pinned?: boolean | undefined; 148 + url?: string | undefined; 149 + audible?: boolean | undefined; 150 + discarded?: boolean | undefined; 151 + autoDiscardable?: boolean | undefined; 152 + groupId?: number | undefined; 153 + mutedInfo?: MutedInfo | undefined; 154 + favIconUrl?: string | undefined; 155 + title?: string | undefined; 156 + } 157 + 158 + export interface TabMoveInfo { 159 + toIndex: number; 160 + windowId: number; 161 + fromIndex: number; 162 + } 163 + 164 + export interface TabDetachInfo { 165 + oldWindowId: number; 166 + oldPosition: number; 167 + } 168 + 169 + export interface TabActiveInfo { 170 + tabId: number; 171 + windowId: number; 172 + } 173 + 174 + export interface TabWindowInfo { 175 + windowId: number; 176 + } 177 + 178 + export interface ZoomChangeInfo { 179 + tabId: number; 180 + oldZoomFactor: number; 181 + newZoomFactor: number; 182 + zoomSettings: ZoomSettings; 183 + } 184 + 185 + export type TabHighlightedEvent = Event< 186 + (highlightInfo: TabHighlightInfo) => void 187 + >; 188 + export type TabRemovedEvent = Event< 189 + (tabId: number, removeInfo: TabRemoveInfo) => void 190 + >; 191 + export type TabUpdatedEvent = Event< 192 + (tabId: number, changeInfo: TabChangeInfo, tab: Tab) => void 193 + >; 194 + export type TabAttachedEvent = Event< 195 + (tabId: number, attachInfo: TabAttachInfo) => void 196 + >; 197 + export type TabMovedEvent = Event< 198 + (tabId: number, moveInfo: TabMoveInfo) => void 199 + >; 200 + export type TabDetachedEvent = Event< 201 + (tabId: number, detachInfo: TabDetachInfo) => void 202 + >; 203 + export type TabCreatedEvent = Event<(tab: Tab) => void>; 204 + export type TabActivatedEvent = Event<(activeInfo: TabActiveInfo) => void>; 205 + export type TabReplacedEvent = Event< 206 + (addedTabId: number, removedTabId: number) => void 207 + >; 208 + export type TabSelectedEvent = Event< 209 + (tabId: number, selectInfo: TabWindowInfo) => void 210 + >; 211 + export type TabZoomChangeEvent = Event< 212 + (ZoomChangeInfo: ZoomChangeInfo) => void 213 + >; 214 + 215 + export interface TabsModule { 216 + onHighlighted: TabHighlightedEvent; 217 + onRemoved: TabRemovedEvent; 218 + onUpdated: TabUpdatedEvent; 219 + onAttached: TabAttachedEvent; 220 + onMoved: TabMovedEvent; 221 + onDetached: TabDetachedEvent; 222 + onCreated: TabCreatedEvent; 223 + onActivated: TabActivatedEvent; 224 + onReplaced: TabReplacedEvent; 225 + onSelectionChanged: TabSelectedEvent; 226 + onActiveChanged: TabSelectedEvent; 227 + onHighlightChanged: TabHighlightedEvent; 228 + onZoomChange: TabZoomChangeEvent; 229 + TAB_ID_NONE: -1; 230 + 231 + executeScript: ( 232 + tabId: number, 233 + details: InjectDetails, 234 + ) => Promise<any[]>; 235 + get: (tabId: number) => Promise<Tab>; 236 + getAllInWindow: (windowId: number) => Promise<Tab>; 237 + getCurrent: () => Promise<Tab>; 238 + getSelected: (windowId: number) => Promise<Tab>; 239 + create: (createProperties: CreateProperties) => Promise<Tab>; 240 + move: ( 241 + tabIds: number[], 242 + moveProperties: MoveProperties, 243 + ) => Promise<Tab[]>; 244 + update: ( 245 + tabId: number, 246 + updateProperties: UpdateProperties, 247 + ) => Promise<Tab>; 248 + remove: (tabIds: number[]) => Promise<void>; 249 + captureVisibleTab: ( 250 + windowId: number, 251 + options: CaptureVisibleTabOptions, 252 + ) => Promise<string>; 253 + reload: ( 254 + tabId: number, 255 + reloadProperties?: ReloadProperties, 256 + ) => Promise<void>; 257 + duplicate: (tabId: number, callback?: (tab?: Tab) => void) => void; 258 + connect: (tabId: number, connectInfo?: ConnectInfo) => Port; 259 + insertCSS: (tabId: number, details: InjectDetails) => Promise<void>; 260 + highlight: ( 261 + highlightInfo: HighlightInfo, 262 + ) => Promise<Window>; 263 + query: (queryInfo: QueryInfo) => Promise<Tab[]>; 264 + detectLanguage: (tabId: number) => Promise<string>; 265 + getZoom: (tabId: number) => Promise<number>; 266 + setZoomSettings: ( 267 + tabId: number, 268 + zoomSettings: ZoomSettings, 269 + ) => Promise<void>; 270 + getZoomSettings: (tabId: number) => Promise<ZoomSettings>; 271 + discard: (tabId?: number) => Promise<Tab>; 272 + goForward: (tabId: number) => Promise<void>; 273 + goBack: (tabId: number) => Promise<void>; 274 + group: (options: GroupOptions) => Promise<number>; 275 + ungroup: (tabIds: number | number[]) => Promise<void>; 276 + sendMessage: <M = any, R = any>( 277 + tabId: number, 278 + message: M, 279 + options?: MessageSendOptions, 280 + responseCallback?: (response: R) => void, 281 + ) => void; 282 + sendRequest: <Request = any, Response = any>( 283 + tabId: number, 284 + request: Request, 285 + responseCallback?: (response: Response) => void, 286 + ) => void; 287 + }
+287
source/utilities/browser_api_interface/modules/web_request.ts
··· 1 + // deno-lint-ignore-file no-empty-interface 2 + 3 + import { EventWithRequiredFilterInAddListener, Function } from './event.ts'; 4 + 5 + export type ResourceType = 6 + | 'main_frame' 7 + | 'sub_frame' 8 + | 'stylesheet' 9 + | 'script' 10 + | 'image' 11 + | 'font' 12 + | 'object' 13 + | 'xmlhttprequest' 14 + | 'ping' 15 + | 'csp_report' 16 + | 'media' 17 + | 'websocket' 18 + | 'other'; 19 + 20 + export interface AuthCredentials { 21 + username: string; 22 + password: string; 23 + } 24 + 25 + export interface HttpHeader { 26 + name: string; 27 + value?: string | undefined; 28 + binaryValue?: ArrayBuffer | undefined; 29 + } 30 + 31 + /** Returns value for event handlers that have the 'blocking' extraInfoSpec applied. Allows the event handler to modify network requests. */ 32 + export interface BlockingResponse { 33 + /** Optional. If true, the request is cancelled. Used in onBeforeRequest, this prevents the request from being sent. */ 34 + cancel?: boolean | undefined; 35 + /** 36 + * Optional. 37 + * Only used as a response to the onBeforeRequest and onHeadersReceived events. If set, the original request is prevented from being sent/completed and is instead redirected to the given URL. Redirections to non-HTTP schemes such as data: are allowed. Redirects initiated by a redirect action use the original request method for the redirect, with one exception: If the redirect is initiated at the onHeadersReceived stage, then the redirect will be issued using the GET method. 38 + */ 39 + redirectUrl?: string | undefined; 40 + /** 41 + * Optional. 42 + * Only used as a response to the onHeadersReceived event. If set, the server is assumed to have responded with these response headers instead. Only return responseHeaders if you really want to modify the headers in order to limit the number of conflicts (only one extension may modify responseHeaders for each request). 43 + */ 44 + responseHeaders?: HttpHeader[] | undefined; 45 + /** Optional. Only used as a response to the onAuthRequired event. If set, the request is made using the supplied credentials. */ 46 + authCredentials?: AuthCredentials | undefined; 47 + /** 48 + * Optional. 49 + * Only used as a response to the onBeforeSendHeaders event. If set, the request is made with these request headers instead. 50 + */ 51 + requestHeaders?: HttpHeader[] | undefined; 52 + } 53 + 54 + /** An object describing filters to apply to webRequest events. */ 55 + export interface RequestFilter { 56 + /** Optional. */ 57 + tabId?: number | undefined; 58 + /** 59 + * A list of request types. Requests that cannot match any of the types will be filtered out. 60 + */ 61 + types?: ResourceType[] | undefined; 62 + /** A list of URLs or URL patterns. Requests that cannot match any of the URLs will be filtered out. */ 63 + urls: string[]; 64 + 65 + /** Optional. */ 66 + windowId?: number | undefined; 67 + } 68 + 69 + /** 70 + * Contains data uploaded in a URL request. 71 + * @since Chrome 23. 72 + */ 73 + export interface UploadData { 74 + /** Optional. An ArrayBuffer with a copy of the data. */ 75 + bytes?: ArrayBuffer | undefined; 76 + /** Optional. A string with the file's path and name. */ 77 + file?: string | undefined; 78 + } 79 + 80 + export interface WebRequestBody { 81 + /** Optional. Errors when obtaining request body data. */ 82 + error?: string | undefined; 83 + /** 84 + * Optional. 85 + * If the request method is POST and the body is a sequence of key-value pairs encoded in UTF8, encoded as either multipart/form-data, or application/x-www-form-urlencoded, this dictionary is present and for each key contains the list of all values for that key. If the data is of another media type, or if it is malformed, the dictionary is not present. An example value of this dictionary is {'key': ['value1', 'value2']}. 86 + */ 87 + formData?: { [key: string]: string[] } | undefined; 88 + /** 89 + * Optional. 90 + * If the request method is PUT or POST, and the body is not already parsed in formData, then the unparsed request body elements are contained in this array. 91 + */ 92 + raw?: UploadData[] | undefined; 93 + } 94 + 95 + export interface WebAuthChallenger { 96 + host: string; 97 + port: number; 98 + } 99 + 100 + export interface ResourceRequest { 101 + url: string; 102 + /** The ID of the request. Request IDs are unique within a browser session. As a result, they could be used to relate different events of the same request. */ 103 + requestId: string; 104 + /** The value 0 indicates that the request happens in the main frame; a positive value indicates the ID of a subframe in which the request happens. If the document of a (sub-)frame is loaded (type is main_frame or sub_frame), frameId indicates the ID of this frame, not the ID of the outer frame. Frame IDs are unique within a tab. */ 105 + frameId: number; 106 + /** ID of frame that wraps the frame which sent the request. Set to -1 if no parent frame exists. */ 107 + parentFrameId: number; 108 + /** The ID of the tab in which the request takes place. Set to -1 if the request isn't related to a tab. */ 109 + tabId: number; 110 + /** 111 + * How the requested resource will be used. 112 + */ 113 + type: ResourceType; 114 + /** The time when this signal is triggered, in milliseconds since the epoch. */ 115 + timeStamp: number; 116 + /** The origin where the request was initiated. This does not change through redirects. If this is an opaque origin, the string 'null' will be used. 117 + * @since Since Chrome 63. 118 + */ 119 + initiator?: string | undefined; 120 + } 121 + 122 + export interface WebRequestDetails extends ResourceRequest { 123 + /** Standard HTTP method. */ 124 + method: string; 125 + } 126 + 127 + export interface WebRequestHeadersDetails extends WebRequestDetails { 128 + /** Optional. The HTTP request headers that are going to be sent out with this request. */ 129 + requestHeaders?: HttpHeader[] | undefined; 130 + } 131 + 132 + export interface WebRequestBodyDetails extends WebRequestDetails { 133 + /** 134 + * Contains the HTTP request body data. Only provided if extraInfoSpec contains 'requestBody'. 135 + * @since Chrome 23. 136 + */ 137 + requestBody: WebRequestBody | null; 138 + } 139 + 140 + export interface WebRequestFullDetails 141 + extends WebRequestHeadersDetails, WebRequestBodyDetails {} 142 + 143 + export interface WebResponseDetails extends ResourceRequest { 144 + /** HTTP status line of the response or the 'HTTP/0.9 200 OK' string for HTTP/0.9 responses (i.e., responses that lack a status line). */ 145 + statusLine: string; 146 + /** 147 + * Standard HTTP status code returned by the server. 148 + * @since Chrome 43. 149 + */ 150 + statusCode: number; 151 + } 152 + 153 + export interface WebResponseHeadersDetails extends WebResponseDetails { 154 + /** Optional. The HTTP response headers that have been received with this response. */ 155 + responseHeaders?: HttpHeader[] | undefined; 156 + method: string /** standard HTTP method i.e. GET, POST, PUT, etc. */; 157 + } 158 + 159 + export interface WebResponseCacheDetails extends WebResponseHeadersDetails { 160 + /** 161 + * Optional. 162 + * The server IP address that the request was actually sent to. Note that it may be a literal IPv6 address. 163 + */ 164 + ip?: string | undefined; 165 + /** Indicates if this response was fetched from disk cache. */ 166 + fromCache: boolean; 167 + } 168 + 169 + export interface WebRedirectionResponseDetails extends WebResponseCacheDetails { 170 + /** The new URL. */ 171 + redirectUrl: string; 172 + } 173 + 174 + export interface WebAuthenticationChallengeDetails 175 + extends WebResponseHeadersDetails { 176 + /** The authentication scheme, e.g. Basic or Digest. */ 177 + scheme: string; 178 + /** The authentication realm provided by the server, if there is one. */ 179 + realm?: string | undefined; 180 + /** The server requesting authentication. */ 181 + challenger: WebAuthChallenger; 182 + /** True for Proxy-Authenticate, false for WWW-Authenticate. */ 183 + isProxy: boolean; 184 + } 185 + 186 + export interface WebResponseErrorDetails extends WebResponseCacheDetails { 187 + /** The error description. This string is not guaranteed to remain backwards compatible between releases. You must not parse and act based upon its content. */ 188 + error: string; 189 + } 190 + 191 + export interface WebRequestBodyEvent 192 + extends 193 + EventWithRequiredFilterInAddListener< 194 + (details: WebRequestBodyDetails) => BlockingResponse | void 195 + > { 196 + addListener( 197 + callback: (details: WebRequestBodyDetails) => BlockingResponse | void, 198 + filter: RequestFilter, 199 + opt_extraInfoSpec?: string[], 200 + ): void; 201 + } 202 + 203 + export interface WebRequestHeadersSynchronousEvent 204 + extends 205 + EventWithRequiredFilterInAddListener< 206 + (details: WebRequestHeadersDetails) => BlockingResponse | void 207 + > { 208 + addListener( 209 + callback: (details: WebRequestHeadersDetails) => BlockingResponse | void, 210 + filter: RequestFilter, 211 + opt_extraInfoSpec?: string[], 212 + ): void; 213 + } 214 + 215 + export interface WebRequestHeadersEvent 216 + extends 217 + EventWithRequiredFilterInAddListener< 218 + (details: WebRequestHeadersDetails) => void 219 + > { 220 + addListener( 221 + callback: (details: WebRequestHeadersDetails) => void, 222 + filter: RequestFilter, 223 + opt_extraInfoSpec?: string[], 224 + ): void; 225 + } 226 + 227 + export interface _WebResponseHeadersEvent<T extends WebResponseHeadersDetails> 228 + extends EventWithRequiredFilterInAddListener<(details: T) => void> { 229 + addListener( 230 + callback: (details: T) => void, 231 + filter: RequestFilter, 232 + opt_extraInfoSpec?: string[], 233 + ): void; 234 + } 235 + 236 + export interface WebResponseHeadersEvent 237 + extends 238 + EventWithRequiredFilterInAddListener< 239 + (details: WebResponseHeadersDetails) => BlockingResponse | void 240 + > { 241 + addListener( 242 + callback: (details: WebResponseHeadersDetails) => BlockingResponse | void, 243 + filter: RequestFilter, 244 + opt_extraInfoSpec?: string[], 245 + ): void; 246 + } 247 + 248 + export interface WebResponseCacheEvent 249 + extends _WebResponseHeadersEvent<WebResponseCacheDetails> {} 250 + 251 + export interface WebRedirectionResponseEvent 252 + extends _WebResponseHeadersEvent<WebRedirectionResponseDetails> {} 253 + 254 + export interface WebAuthenticationChallengeEvent 255 + extends 256 + EventWithRequiredFilterInAddListener< 257 + ( 258 + details: WebAuthenticationChallengeDetails, 259 + callback?: (response: BlockingResponse) => void, 260 + ) => void 261 + > { 262 + addListener( 263 + callback: ( 264 + details: WebAuthenticationChallengeDetails, 265 + callback?: (response: BlockingResponse) => void, 266 + ) => void, 267 + filter: RequestFilter, 268 + opt_extraInfoSpec?: string[], 269 + ): void; 270 + } 271 + 272 + export interface WebResponseErrorEvent 273 + extends _WebResponseHeadersEvent<WebResponseErrorDetails> {} 274 + 275 + export interface WebRequest { 276 + MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES: number; 277 + handlerBehaviorChanged: (callback?: Function) => void; 278 + onBeforeRequest: WebRequestBodyEvent; 279 + onBeforeSendHeaders: WebRequestHeadersSynchronousEvent; 280 + onSendHeaders: WebRequestHeadersEvent; 281 + onHeadersReceived: WebResponseHeadersEvent; 282 + onAuthRequired: WebAuthenticationChallengeEvent; 283 + onResponseStarted: WebResponseCacheEvent; 284 + onBeforeRedirect: WebRedirectionResponseEvent; 285 + onCompleted: WebResponseCacheEvent; 286 + onErrorOccurred: WebResponseErrorEvent; 287 + }
+100
source/utilities/browser_api_interface/modules/windows.ts
··· 1 + import type { Tab } from './tabs.ts'; 2 + import type { Event } from './event.ts'; 3 + 4 + export interface Window { 5 + tabs?: Tab[] | undefined; 6 + top?: number | undefined; 7 + height?: number | undefined; 8 + width?: number | undefined; 9 + state?: windowStateEnum | undefined; 10 + focused: boolean; 11 + alwaysOnTop: boolean; 12 + incognito: boolean; 13 + type?: windowTypeEnum | undefined; 14 + id?: number | undefined; 15 + left?: number | undefined; 16 + sessionId?: string | undefined; 17 + } 18 + 19 + export interface QueryOptions { 20 + populate?: boolean | undefined; 21 + windowTypes?: windowTypeEnum[] | undefined; 22 + } 23 + 24 + export interface CreateData { 25 + tabId?: number | undefined; 26 + url?: string | string[] | undefined; 27 + top?: number | undefined; 28 + height?: number | undefined; 29 + width?: number | undefined; 30 + focused?: boolean | undefined; 31 + incognito?: boolean | undefined; 32 + type?: createTypeEnum | undefined; 33 + left?: number | undefined; 34 + state?: windowStateEnum | undefined; 35 + setSelfAsOpener?: boolean | undefined; 36 + } 37 + 38 + export interface UpdateInfo { 39 + top?: number | undefined; 40 + drawAttention?: boolean | undefined; 41 + height?: number | undefined; 42 + width?: number | undefined; 43 + state?: windowStateEnum | undefined; 44 + focused?: boolean | undefined; 45 + left?: number | undefined; 46 + } 47 + 48 + export interface WindowEventFilter { 49 + windowTypes: windowTypeEnum[]; 50 + } 51 + 52 + export interface WindowIdEvent extends Event<(windowId: number) => void> { 53 + addListener( 54 + callback: (windowId: number) => void, 55 + filters?: WindowEventFilter, 56 + ): void; 57 + } 58 + 59 + export interface WindowReferenceEvent extends Event<(window: Window) => void> { 60 + addListener( 61 + callback: (window: Window) => void, 62 + filters?: WindowEventFilter, 63 + ): void; 64 + } 65 + export type createTypeEnum = 'normal' | 'popup' | 'panel'; 66 + export type windowStateEnum = 67 + | 'normal' 68 + | 'minimized' 69 + | 'maximized' 70 + | 'fullscreen' 71 + | 'locked-fullscreen'; 72 + export type windowTypeEnum = 'normal' | 'popup' | 'panel' | 'app' | 'devtools'; 73 + 74 + export interface WindowsModule { 75 + WINDOW_ID_CURRENT: -2; 76 + WINDOW_ID_NONE: -1; 77 + onRemoved: WindowIdEvent; 78 + onCreated: WindowReferenceEvent; 79 + onFocusChanged: WindowIdEvent; 80 + onBoundsChanged: WindowReferenceEvent; 81 + get: ( 82 + windowId: number, 83 + queryOptions?: QueryOptions, 84 + ) => Promise<Window>; 85 + getCurrent: ( 86 + queryOptions?: QueryOptions, 87 + ) => Promise<Window>; 88 + create: (createData?: CreateData) => Promise<Window>; 89 + getAll: ( 90 + queryOptions?: QueryOptions, 91 + ) => Promise<Window[]>; 92 + update: ( 93 + windowId: number, 94 + updateInfo: UpdateInfo, 95 + ) => Promise<Window>; 96 + remove: (windowId: number) => Promise<void>; 97 + getLastFocused: ( 98 + queryOptions: QueryOptions, 99 + ) => Promise<Window>; 100 + }
+1 -1
source/utilities/create_favicon_url.ts
··· 1 - import { isFirefox } from './browser_api.ts'; 1 + import { isFirefox } from './predicates.ts'; 2 2 3 3 export const ICON_SIZE = 256; // Larger will causes problems in Google Chrome 4 4 const VERTICAL_OFFSET = (isFirefox() ? 40 : 0); // ff is off-center
+31
source/utilities/predicates.ts
··· 9 9 filter.startsWith('/') && 10 10 filter.endsWith('/'); 11 11 } 12 + 13 + /** 14 + * What browser is this? 15 + * @param {string} toCheck to check 16 + */ 17 + export function isBrowser(toCheck: 'CHROME' | 'FIREFOX'): boolean { 18 + let currentBrowser = 'CHROME'; 19 + try { 20 + // Use try block, since userAgent not guaranteed to exist. 21 + // If fail, assume Chromium 22 + // deno-lint-ignore no-explicit-any 23 + const userAgent: string = (navigator as any)?.userAgent || ''; 24 + if (userAgent.indexOf('Firefox') > 0) { 25 + currentBrowser = 'FIREFOX'; 26 + } 27 + } catch (_) { 28 + // Do nothing 29 + } 30 + 31 + if (!toCheck) currentBrowser; 32 + if (toCheck === 'CHROME' && currentBrowser === 'CHROME') return true; 33 + if (toCheck === 'FIREFOX' && currentBrowser === 'FIREFOX') return true; 34 + return false; 35 + } 36 + 37 + export function isChrome(): boolean { 38 + return isBrowser('CHROME'); 39 + } 40 + export function isFirefox(): boolean { 41 + return isBrowser('FIREFOX'); 42 + }