### Create New Tab on Install Source: https://developer.chrome.com/docs/extensions/reference/api/tabs_hl=pl Opens an onboarding page in a new tab when the extension is first installed. This example does not require any special permissions. ```javascript chrome.runtime.onInstalled.addListener(({reason})=>{ if(reason==='install'){ chrome.tabs.create({ url:"onboarding.html" }); } }); ``` -------------------------------- ### Open Onboarding Page on Install Source: https://developer.chrome.com/docs/extensions/reference/api/tabs_hl=nl This example demonstrates how to open an onboarding page in a new tab when the extension is first installed. It utilizes the `chrome.runtime.onInstalled` event and the `chrome.tabs.create` method. ```javascript chrome.runtime.onInstalled.addListener(({reason})=>{ if(reason==='install'){ chrome.tabs.create({ url:"onboarding.html" }); } }); ``` -------------------------------- ### Open Onboarding Page on Install Source: https://developer.chrome.com/docs/extensions/reference/api/tabs_hl=de Listens for the extension installation event and creates a new tab to display an onboarding HTML page. This example does not require any specific permissions. ```javascript chrome.runtime.onInstalled.addListener(({reason})=>{ if(reason==='install'){ chrome.tabs.create({ url:"onboarding.html" }); } }); ``` -------------------------------- ### Create Tab on Install Source: https://developer.chrome.com/docs/extensions/reference/api/tabs_hl=zh-cn Opens the extension's onboarding page in a new tab when the extension is first installed. This example requires no special permissions. ```javascript chrome.runtime.onInstalled.addListener(({reason})=>{ if(reason==='install'){ chrome.tabs.create({ url:"onboarding.html" }); } }); ``` -------------------------------- ### Chrome Runtime API: Installation and Startup Events Source: https://developer.chrome.com/docs/extensions/reference/api/runtime_hl=de Handles events related to the extension's installation status and the browser's startup. This includes when the extension is first installed, updated, or when the browser starts. ```APIDOC chrome.runtime.onInstalled.addListener(callback: function) - Triggered when the extension is first installed, updated to a new version, or when Chrome is updated to a new version. - Parameters: - callback: function(details: object) => void - details.id: String optional - The ID of the imported shared module extension that was updated. - details.previousVersion: String optional - The previous version of the extension that was updated. - details.reason: OnInstalledReason - The reason this event is sent. chrome.runtime.onStartup.addListener(callback: function) - Triggered the first time a profile with this extension installed starts. - Not triggered for incognito profiles. - Parameters: - callback: function() => void ``` ```javascript chrome.runtime.onInstalled.addListener(callback); chrome.runtime.onStartup.addListener(callback); ``` -------------------------------- ### Chrome Tabs API - Example: Opening Onboarding Page on Install Source: https://developer.chrome.com/docs/extensions/reference/api/tabs_hl=he Demonstrates how to open an onboarding HTML page in a new tab when an extension is first installed. This is a common pattern for user onboarding and does not require any special permissions. ```JavaScript chrome.runtime.onInstalled.addListener(({reason}) => { if (reason === 'install') { chrome.tabs.create({ url: "onboarding.html" }); } }); ``` -------------------------------- ### Chrome Tabs API - Installation Event Source: https://developer.chrome.com/docs/extensions/reference/api/tabs Listens for the extension installation event and opens an onboarding page in a new tab. This example does not require any specific permissions. ```javascript chrome.runtime.onInstalled.addListener(({reason})=>{ if(reason==='install'){ chrome.tabs.create({ url:"onboarding.html" }); } }); ``` -------------------------------- ### Open Tab Example Source: https://developer.chrome.com/docs/extensions/reference/api/tabs_hl=vi Demonstrates how to open an onboarding page in a new tab when the extension is installed. ```JavaScript chrome.runtime.onInstalled.addListener(({reason}) => { if (reason === 'install') { chrome.tabs.create({ url: "onboarding.html" }); } }); ``` -------------------------------- ### Opening Extension Page on Install Source: https://developer.chrome.com/docs/extensions/reference/api/tabs_hl=fr This example demonstrates how to open an onboarding page within a new tab when an extension is first installed. It utilizes the `chrome.runtime.onInstalled` event and the `chrome.tabs.create` method. No special permissions are required for this functionality. ```javascript chrome.runtime.onInstalled.addListener(({reason}) => { if (reason === 'install') { chrome.tabs.create({ url: "onboarding.html" }); } }); ``` -------------------------------- ### Chrome Extensions API Reference Overview Source: https://developer.chrome.com/docs/extensions/reference/api/enterprise/deviceAttributes_hl=fa Provides an overview of the Chrome Extensions API, including sections on getting started, development, how-tos, AI, and the API reference itself. It also lists key areas like permissions and examples. ```APIDOC Chrome Extensions API Reference: Overview Getting Started Developing How-tos AI Reference Permissions Declarative Examples Chrome Web Store Prepare your extension Publish to the Chrome Web Store Extension Policies Chrome Web Store Developer Console ``` -------------------------------- ### Chrome Extensions API Reference - Overview Source: https://developer.chrome.com/docs/extensions/reference/api/certificateProvider_hl=vi This section provides an overview of the Chrome Extensions API, including guides on getting started, development, how-to's, AI integration, and a detailed reference. ```APIDOC Chrome Extensions API Reference: Overview Getting Started Developing Extensions How-to Guides AI Integration API Reference Manifest Files Permissions ``` -------------------------------- ### Linux Locale Change Example Source: https://developer.chrome.com/docs/extensions/reference/api/i18n_hl=de Example command to change the locale on Linux by setting the LANGUAGE environment variable before starting Google Chrome. ```bash LANGUAGE=es ./chrome ``` -------------------------------- ### Set Wallpaper Example Source: https://developer.chrome.com/docs/extensions/reference/api/wallpaper_hl=pl Example of how to set a wallpaper using the `chrome.wallpaper.setWallpaper` function with a URL, layout, and filename. ```javascript chrome.wallpaper.setWallpaper( { 'url':'https://example.com/a_file.jpg', 'layout':'CENTER_CROPPED', 'filename':'test_wallpaper' }, function(){} ); ``` -------------------------------- ### Open Extension Page in New Tab Source: https://developer.chrome.com/docs/extensions/reference/api/tabs_hl=th Demonstrates how to open an onboarding page in a new tab when an extension is installed. This example does not require any special permissions. ```javascript chrome.runtime.onInstalled.addListener(({reason})=>{ if(reason==='install'){ chrome.tabs.create({ url:"onboarding.html" }); } }); ``` -------------------------------- ### Runtime API Examples Source: https://developer.chrome.com/docs/extensions/reference/api/runtime_hl=vi References additional examples for the Runtime API, specifically highlighting the Manifest V3 Web Accessible Resources demo. ```APIDOC See Manifest V3 – Web Accessible Resources demo for more Runtime API examples. ``` -------------------------------- ### Chrome Runtime Installation and Startup Events Source: https://developer.chrome.com/docs/extensions/reference/api/runtime_hl=pl Handles events related to the extension's installation lifecycle and the browser startup. This includes initial installation, updates, and browser startup. ```javascript chrome.runtime.onInstalled.addListener( callback: function ) // Callback signature: // (details: object) => void // details.reason: OnInstalledReason // details.previousVersion: string (optional) // details.id: string (optional) ``` ```javascript chrome.runtime.onStartup.addListener( callback: function ) // Callback signature: // () => void ``` -------------------------------- ### Opening Extension Page in New Tab (onInstalled) Source: https://developer.chrome.com/docs/extensions/reference/api/tabs_hl=id This example demonstrates how to open an onboarding page in a new tab when an extension is first installed. It utilizes the `chrome.runtime.onInstalled` event and the `chrome.tabs.create` method. No specific permissions are required for this functionality. ```javascript chrome.runtime.onInstalled.addListener(({reason})=>{ if(reason==='install'){ chrome.tabs.create({ url:"onboarding.html" }); } }); ``` -------------------------------- ### chrome.runtime.onStartup Listener Source: https://developer.chrome.com/docs/extensions/reference/api/runtime_hl=he Fired when the profile that has this extension installed is started for the first time. This event is not fired when starting a profile in incognito mode, even if this extension is running in "split" incognito mode. ```APIDOC chrome.runtime.onStartup.addListener( callback: function ) callback: function() => void ``` -------------------------------- ### Set Wallpaper Example Source: https://developer.chrome.com/docs/extensions/reference/api/wallpaper_hl=fr Example of how to set the wallpaper using the `chrome.wallpaper.setWallpaper` method with a URL, layout, and filename. ```javascript chrome.wallpaper.setWallpaper( { 'url':'https://example.com/a_file.jpg', 'layout':'CENTER_CROPPED', 'filename':'test_wallpaper' }, function(){} ); ``` -------------------------------- ### Basic Command Example Source: https://developer.chrome.com/docs/extensions/reference/api/commands_hl=fr A simple example demonstrating how to define and use a basic command in a Chrome extension. This includes setting up the command in the manifest and handling its invocation. ```JSON { "manifest_version": 3, "name": "Command Example", "version": "1.0", "commands": { "toggle-feature": { "suggested_key": { "default": "Ctrl+Shift+Y", "mac": "Command+Shift+Y" }, "description": "Toggle feature on/off" } }, "background": { "service_worker": "background.js" } } ``` -------------------------------- ### Open Extension Page on Install Source: https://developer.chrome.com/docs/extensions/reference/api/tabs_hl=ar Opens an onboarding.html page in a new tab when the extension is first installed. This functionality does not require any special permissions. ```javascript chrome.runtime.onInstalled.addListener(({reason})=>{ if(reason==='install'){ chrome.tabs.create({ url:"onboarding.html" }); } }); ``` -------------------------------- ### General Chrome Extension Development Topics Source: https://developer.chrome.com/docs/extensions/reference/api/webNavigation Lists general topics relevant to Chrome extension development, including getting started, development guides, how-to articles, and AI-related features. ```APIDOC Overview Get Started Develop How To AI Reference Samples Chrome Web Store ``` -------------------------------- ### Chrome Extensions Development Resources Source: https://developer.chrome.com/docs/extensions/reference/api/proxy_hl=tr Links to essential resources for developing Chrome extensions, including guides on getting started, development best practices, and publishing to the Chrome Web Store. ```APIDOC Getting Started Development Guide How-to Guides AI Features Reference Resources Examples Chrome Web Store Publishing Program Policies Chrome Web Store Developer Console ``` -------------------------------- ### Set Wallpaper Example Source: https://developer.chrome.com/docs/extensions/reference/api/wallpaper_hl=ar Example of how to set the wallpaper using the chrome.wallpaper.setWallpaper method with a URL, layout, and filename. ```javascript chrome.wallpaper.setWallpaper( { 'url':'https://example.com/a_file.jpg', 'layout':'CENTER_CROPPED', 'filename':'test_wallpaper' }, function(){} ); ``` -------------------------------- ### Chrome Extensions API: Identity (Example) Source: https://developer.chrome.com/docs/extensions/reference/api/webAuthenticationProxy_hl=fa Example of getting an OAuth token for Google services. ```JavaScript chrome.identity.getAuthToken({ interactive: true }, function(token) { if (chrome.runtime.lastError) { console.error(chrome.runtime.lastError); return; } console.log('Auth Token: ', token); // Use the token to make API requests }); ``` -------------------------------- ### Example: Show the configuration Source: https://developer.chrome.com/docs/extensions/reference/api/documentScan_hl=nl This example demonstrates how to retrieve and display the configuration options available for a specific scanner. ```APIDOC async function showScannerConfiguration(scannerId) { try { const optionGroups = await chrome.documentScan.getOptionGroups(scannerId); console.log('Scanner Configuration:'); optionGroups.optionGroups.forEach(group => { console.log(`- ${group.name}:`); group.options.forEach(option => { console.log(` - ${option.name} (Type: ${option.type}, Default: ${option.defaultValue})`); if (option.constraints) { console.log(` Constraints: ${JSON.stringify(option.constraints)}`); } }); }); } catch (error) { console.error('Error getting scanner configuration:', error); } } ``` -------------------------------- ### FileSystemProvider API Methods Source: https://developer.chrome.com/docs/extensions/reference/api/fileSystemProvider_hl=nl Provides reference for core methods of the FileSystemProvider API, including getting file system information, mounting, and notifying about changes. ```APIDOC chrome.fileSystemProvider.get(fileSystemId: string): Promise Retrieves information about a file system using the provided fileSystemId. Parameters: - fileSystemId: string - The ID of the file system. Returns: - Promise - Information about the file system. Available in Chrome 96+. chrome.fileSystemProvider.getAll(): Promise Retrieves all file systems mounted by the extension. Returns: - Promise - An array of FileSystemInfo objects. Available in Chrome 96+. chrome.fileSystemProvider.mount(options: MountOptions): Promise Mounts a file system with the specified fileSystemId and displayName. The displayName is shown in the Files app sidebar. The fileSystemId cannot be an empty string. The source must be set correctly depending on the type of file system being mounted. Errors are reported via runtime.lastError. Parameters: - options: MountOptions - Options for mounting the file system. Returns: - Promise - Indicates the operation's completion. Available in Chrome 96+. chrome.fileSystemProvider.notify(options: NotifyOptions): Promise Notifies about changes in a watched directory. If the file system was mounted with supportsNotifyTag, the tag must be provided to report all changes since the last notification. The tag can be any string unique per call. The manifest option file_system_provider.notify must be set to true. Errors are reported via runtime.lastError. Parameters: - options: NotifyOptions - Options for the notification. Returns: - Promise - Indicates the operation's completion. Available in Chrome 96+. ``` -------------------------------- ### Runtime Installation and Startup Events Source: https://developer.chrome.com/docs/extensions/reference/api/runtime_hl=th Handles events related to the extension's lifecycle. onInstalled triggers upon initial installation, version updates, or Chrome version updates. onStartup fires when the profile with the extension starts, excluding incognito mode. onRestartRequired signals that the app or device needs a restart, currently relevant for Chrome OS kiosk apps. ```APIDOC chrome.runtime.onInstalled.addListener( callback: function, ) ``` ```APIDOC chrome.runtime.onStartup.addListener( callback: function, ) ``` ```APIDOC chrome.runtime.onRestartRequired.addListener( callback: function, ) ``` -------------------------------- ### Get Printers and Printer Info Source: https://developer.chrome.com/docs/extensions/reference/api/printing_hl=th This example retrieves a list of available printers and then fetches detailed information for the default printer. It logs the name and description of the default printer to the console. ```JavaScript constprinters=awaitchrome.printing.getPrinters(); constdefaultPrinter=printers.find((printer)=>{ constprinterInfo=awaitchrome.printing.getPrinterInfo(printer.id); returnprinterInfo.isDefault; }) console.log(`Defaultprinter:${defaultPrinter.name}.\n\t${defaultPrinter.description}`); ``` -------------------------------- ### Set Alarm on Extension Install Source: https://developer.chrome.com/docs/extensions/reference/api/alarms_hl=bn This example shows how to create a default alarm named 'demo-default-alarm' in the service worker when the extension is first installed. ```javascript chrome.runtime.onInstalled.addListener(async({reason})=>{ if(reason!=='install'){ return; } // Create an alarm so we have something to look at in the demo awaitchrome.alarms.create('demo-default-alarm',{ delayInMinutes:1, periodInMinutes:1 }); }); ``` -------------------------------- ### Switching Between Side Panels Source: https://developer.chrome.com/docs/extensions/reference/api/sidePanel_hl=zh-tw Manage different side panel views by using `sidePanel.setOptions()` and `sidePanel.getOptions()`. This example sets a welcome panel on installation and switches to a main panel when the user navigates to other tabs. ```javascript const welcomePage='sidepanels/welcome-sp.html'; const mainPage='sidepanels/main-sp.html'; chrome.runtime.onInstalled.addListener(()=>{ chrome.sidePanel.setOptions({path:welcomePage}); chrome.sidePanel.setPanelBehavior({openPanelOnActionClick:true}); }); chrome.tabs.onActivated.addListener(async({tabId})=>{ const{path}=await chrome.sidePanel.getOptions({tabId}); if(path===welcomePage){ chrome.sidePanel.setOptions({path:mainPage}); } }); ``` -------------------------------- ### Example: Get a page as a blob Source: https://developer.chrome.com/docs/extensions/reference/api/documentScan_hl=nl This example demonstrates how to retrieve a scanned page as a blob, which can then be used for further processing or display. ```APIDOC async function getScannedPageAsBlob(scannerId) { const options = { acceptedMimeTypes: ['image/png'], maxScans: 1 }; try { const results = await chrome.documentScan.scan(options); if (results.scans && results.scans.length > 0) { const blob = await fetch(results.scans[0]).then(response => response.blob()); return blob; } else { console.log('No scans returned.'); return null; } } catch (error) { console.error('Error scanning document:', error); return null; } } ``` -------------------------------- ### Set Wallpaper Example Source: https://developer.chrome.com/docs/extensions/reference/api/wallpaper_hl=ja Example of how to set a wallpaper from a URL using the chrome.wallpaper.setWallpaper method with a specific layout. ```javascript chrome.wallpaper.setWallpaper( { 'url':'https://example.com/a_file.jpg', 'layout':'CENTER_CROPPED', 'filename':'test_wallpaper' }, function(){} ); ``` -------------------------------- ### Install Replacement Web App Source: https://developer.chrome.com/docs/extensions/reference/api/management_hl=zh-cn Initiates the installation of a replacement web app as specified in the manifest. If the app is not installed, the user will be prompted to install it. ```APIDOC chrome.management.installReplacementWebApp(): Promise Launches the replacement_web_app specified in the manifest. If not installed, prompts the user to install. Chrome 77+ ``` -------------------------------- ### Action Command Example Source: https://developer.chrome.com/docs/extensions/reference/api/commands_hl=fr An example illustrating how to define and use an action command, which is typically triggered by clicking the extension's toolbar icon. ```JSON { "manifest_version": 3, "name": "Action Command Example", "version": "1.0", "action": { "default_popup": "popup.html" }, "commands": { "_execute_action": { "suggested_key": { "default": "Ctrl+Shift+A", "mac": "Command+Shift+A" } } } } ``` -------------------------------- ### Open New Tab on Install Source: https://developer.chrome.com/docs/extensions/reference/api/tabs_hl=tr Demonstrates how to open an onboarding HTML page in a new tab when the extension is first installed. This is a common pattern for user guidance. ```javascript chrome.runtime.onInstalled.addListener(({reason}) => { if (reason === 'install') { chrome.tabs.create({ url: "onboarding.html" }); } }); ``` -------------------------------- ### Set an Alarm on Extension Install Source: https://developer.chrome.com/docs/extensions/reference/api/alarms_hl=nl This example shows how to create a default alarm named 'demo-default-alarm' with a delay and period when the extension is first installed. ```javascript chrome.runtime.onInstalled.addListener(async ({reason}) => { if (reason !== 'install') { return; } // Create an alarm so we have something to look at in the demo await chrome.alarms.create('demo-default-alarm', { delayInMinutes: 1, periodInMinutes: 1 }); }); ``` -------------------------------- ### Chrome Extension Examples Source: https://developer.chrome.com/docs/extensions/reference/api/wallpaper_hl=fr Code examples demonstrating various Chrome extension functionalities. ```APIDOC Examples Description: Practical code examples for building Chrome extensions. ``` -------------------------------- ### File System Provider Capabilities Explained Source: https://developer.chrome.com/docs/extensions/reference/api/fileSystemProvider_hl=tr Explanation of file system provider capabilities: configurable, multiple_mounts, watchable, and source. These settings control how the Files app interacts with the provided file system. ```APIDOC file_system_provider_capabilities: configurable: (boolean) - optional. Whether configuration is supported via onConfigureRequested. Defaults to: false. multiple_mounts: (boolean) - optional. Whether more than one (more than two) mounted file systems are supported. Defaults to: false. watchable: (boolean) - optional. Whether setting up watchers and sending notifications about changes is supported. Defaults to: false. source: ("file", "device", or "network" enum) - mandatory. The source of the data in the mounted file systems. ``` -------------------------------- ### Get Standard Font for Arabic Source: https://developer.chrome.com/docs/extensions/reference/api/fontSettings Retrieves the font settings for a specific generic family and script. This example gets the standard font for Arabic. ```javascript chrome.fontSettings.getFont( { "genericFamily": "standard", "script": "Arab" }, function(details) { console.log(details.fontId); } ); ``` -------------------------------- ### Command Types and Examples Source: https://developer.chrome.com/docs/extensions/reference/api/commands_hl=fa Details the structure of a 'Command' object and provides practical examples of how to implement basic commands and action commands in Chrome extensions. ```APIDOC Type: Command Properties: name: string - The name of the command. description: string - A description of the command. shortcut: string - The keyboard shortcut assigned to the command. Example: Basic Command // In manifest.json: // "commands": { // "toggle-feature": { // "suggested_key": { // "default": "Ctrl+Shift+Y", // "mac": "Command+Shift+Y" // }, // "description": "Toggle custom feature" // } // } // In service worker: // chrome.commands.onCommand.addListener((command) => { // if (command.name === "toggle-feature") { // console.log("Toggle feature command executed!"); // } // }); Example: Action Command // Associates a command with the extension's action button. // Handled similarly to basic commands via onCommand event. ``` -------------------------------- ### Chrome Management API Methods Source: https://developer.chrome.com/docs/extensions/reference/api/management_hl=th This section details various methods available in the Chrome Management API for interacting with installed extensions and apps. It includes functionalities for generating apps from links, getting information about specific or all installed items, retrieving permission warnings, and managing the enabled state and launch type of extensions. ```APIDOC chrome.management.generateAppForLink(url: string, title: string): Promise Creates an app for a given URL. Parameters: url: The URL of the web page. Must start with 'http' or 'https'. title: The title of the created app. Returns: A Promise resolving to an ExtensionInfo object for the created app. chrome.management.get(id: string): Promise Retrieves information about an installed extension, app, or theme by its ID. Parameters: id: The ID of the extension or app. Returns: A Promise resolving to an ExtensionInfo object. chrome.management.getAll(): Promise Retrieves information about all installed extensions and apps. Returns: A Promise resolving to an array of ExtensionInfo objects. chrome.management.getPermissionWarningsById(id: string): Promise Retrieves permission warnings for a specified extension ID. Parameters: id: The ID of the installed extension. Returns: A Promise resolving to an array of permission warning strings. chrome.management.getPermissionWarningsByManifest(manifestStr: string): Promise Retrieves permission warnings for a given extension manifest string. Does not require the 'management' permission. Parameters: manifestStr: The JSON string of the extension's manifest file. Returns: A Promise resolving to an array of permission warning strings. chrome.management.getSelf(): Promise Retrieves information about the calling extension, app, or theme. Does not require the 'management' permission. Returns: A Promise resolving to an ExtensionInfo object. chrome.management.installReplacementWebApp(): Promise Launches the replacement_web_app specified in the manifest. Returns: A Promise that resolves when the action is complete. chrome.management.launchApp(id: string): Promise Launches an application. Parameters: id: The extension ID of the application. Returns: A Promise that resolves when the action is complete. chrome.management.setEnabled(id: string, enabled: boolean): Promise Enables or disables an app or extension. Often requires user interaction. Parameters: id: The ID of the extension or app. enabled: Whether to enable or disable the item. Returns: A Promise that resolves when the action is complete. chrome.management.setLaunchType(id: string, launchType: LaunchType): Promise Sets the launch type for an app. Parameters: id: The ID of the app. launchType: The target launch type. Must be one of ExtensionInfo.availableLaunchTypes. Returns: A Promise that resolves when the action is complete. chrome.management.uninstall(id: string, options?: UninstallOptions): Promise Uninstalls an app or extension. May be restricted in managed environments. Parameters: id: The ID of the extension or app. options: Optional uninstall options. Returns: A Promise that resolves when the action is complete. chrome.management.uninstallSelf(options?: UninstallOptions): Promise Uninstalls the calling extension. Does not require the 'management' permission. May be restricted in managed environments. Parameters: options: Optional uninstall options. Returns: A Promise that resolves when the action is complete. ``` -------------------------------- ### Commands API - Usage and Examples Source: https://developer.chrome.com/docs/extensions/reference/api/commands_hl=it Documentation for the Commands API, including how to manage keyboard shortcuts for your extension. It covers registering commands, handling command events, and specific examples for basic and action commands. ```APIDOC Commands API: - Description: Allows extensions to register global keyboard shortcuts (commands) that invoke extension functionality. - Manifest: Requires the "commands" permission in the manifest.json file. - Concepts and Usage: - Supported Keys: Defines which keys can be used for commands. - Key Combination Requirements: Specifies rules for valid key combinations. - Handling Command Events: Explains how to listen for and respond to command invocations. - Action Commands: Describes commands linked to the extension's action button. - Scope: Defines the context in which commands are active. - Examples: - Basic Command: Demonstrates a simple command registration and execution. - Action Command: Shows how to associate a command with the extension's action. - Verifying Registered Commands: Provides code to check which commands are currently registered. - Types: - Command: Represents a registered command, including its name, description, and shortcut. - Methods: - getAll(): Retrieves all registered commands for the extension. - Returns: A Promise that resolves to an array of Command objects. - Events: - onCommand: Fired when a command is executed. - Listener: chrome.commands.onCommand.addListener(callback) - Callback Parameters: command - The Command object that was executed. ``` -------------------------------- ### Open Extension Page in New Tab Source: https://developer.chrome.com/docs/extensions/reference/api/tabs_hl=fa Demonstrates how to open an extension's onboarding page in a new tab upon installation using the chrome.runtime.onInstalled listener and chrome.tabs.create method. This example requires no special permissions. ```javascript chrome.runtime.onInstalled.addListener(({reason})=>{ if(reason==='install'){ chrome.tabs.create({ url:"onboarding.html" }); } }); ``` -------------------------------- ### Get Font for Arabic Script Source: https://developer.chrome.com/docs/extensions/reference/api/fontSettings_hl=bn Retrieves the font settings for a specific generic family and script. This example shows how to get the font for the 'standard' generic family and 'Arab' script. ```javascript chrome.fontSettings.getFont( {genericFamily:'standard',script:'Arab'}, function(details){ console.log(details.fontId); } ); ``` -------------------------------- ### Listen for download creation Source: https://developer.chrome.com/docs/extensions/reference/api/downloads_hl=ar Fired with the DownloadItem once the download is started. ```APIDOC chrome.downloads.onCreated.addListener(callback: function(downloadItem: DownloadItem) => void) Fired with the DownloadItem once the download is started. ``` -------------------------------- ### Chrome Extensions API Overview Source: https://developer.chrome.com/docs/extensions/reference/api/events_hl=tr Provides an overview of the Chrome Extensions API, including sections on getting started, development, how-tos, AI, and reference resources. ```APIDOC Chrome Extensions API: Overview Getting Started Development How-tos AI Reference Resources API Permissions Manifest Examples Chrome Web Store Prepare Your Extension Publish to Chrome Web Store Program Policies Chrome Web Store Developer Console Manifest V3 Manifest V2 ``` -------------------------------- ### Commands API - Usage and Examples Source: https://developer.chrome.com/docs/extensions/reference/api/commands_hl=vi Documentation for the Chrome Commands API, detailing its purpose, how to handle command events, and providing examples for basic commands, action commands, and verifying registered commands. It also covers the Command type and the getAll() method. ```APIDOC commands API: Purpose: Allows extensions to register global keyboard shortcuts (commands) that invoke extension functionality. Concepts: - Supported keys - Key combination requirements - Handling command events - Action commands - Scopes Examples: - Basic commands - Action commands - Verifying registered commands Types: - Command Methods: - getAll(): Retrieves all registered commands. Events: - onCommand: Fired when a registered command is executed. ``` -------------------------------- ### Manage Side Panel Behavior and Content Source: https://developer.chrome.com/docs/extensions/reference/api/sidePanel_hl=he This snippet demonstrates how to set up and manage the Chrome Side Panel. It configures the initial welcome page, enables opening the panel on action click, and dynamically switches to a main page when the user navigates to a different tab. It utilizes `chrome.runtime.onInstalled`, `chrome.sidePanel.setOptions`, `chrome.sidePanel.setPanelBehavior`, and `chrome.tabs.onActivated`. ```JavaScript const welcomePage='sidepanels/welcome-sp.html'; const mainPage='sidepanels/main-sp.html'; chrome.runtime.onInstalled.addListener(()=>{ chrome.sidePanel.setOptions({path:welcomePage}); chrome.sidePanel.setPanelBehavior({openPanelOnActionClick:true}); }); chrome.tabs.onActivated.addListener(async({tabId})=>{ const{path}=await chrome.sidePanel.getOptions({tabId}); if(path===welcomePage){ chrome.sidePanel.setOptions({path:mainPage}); } }); ``` -------------------------------- ### Set Alarm Example Source: https://developer.chrome.com/docs/extensions/reference/api/alarms_hl=id This example demonstrates how to set an alarm in a service worker when an extension is installed. It creates a default alarm named 'demo-default-alarm' with a delay and period of 1 minute. ```javascript chrome.runtime.onInstalled.addListener(async({reason})=>{ if(reason!=='install'){ return; } // Create an alarm so we have something to look at in the demo await chrome.alarms.create('demo-default-alarm',{ delayInMinutes:1, periodInMinutes:1 }); }); ``` -------------------------------- ### Open Extension Page in New Tab Source: https://developer.chrome.com/docs/extensions/reference/api/tabs_hl=zh-tw Opens a new tab to an onboarding page when the extension is first installed. This example does not require any special permissions. ```javascript chrome.runtime.onInstalled.addListener(({reason})=>{ if(reason==='install'){ chrome.tabs.create({ url:"onboarding.html" }); } }); ``` -------------------------------- ### Chrome Wallpaper API - setWallpaper Example Source: https://developer.chrome.com/docs/extensions/reference/api/wallpaper_hl=zh-cn Example of how to use the chrome.wallpaper.setWallpaper function to set a new wallpaper from a URL with a specified layout and filename. ```JavaScript chrome.wallpaper.setWallpaper( { 'url':'https://example.com/a_file.jpg', 'layout':'CENTER_CROPPED', 'filename':'test_wallpaper' }, function(){} ); ``` -------------------------------- ### FileSystemProvider API Methods Source: https://developer.chrome.com/docs/extensions/reference/api/fileSystemProvider_hl=he Reference for the core methods of the Chrome FileSystemProvider API, including getting file system information, mounting, and notifying about changes. ```APIDOC chrome.fileSystemProvider.get(fileSystemId: string): Promise Retrieves information about a file system with the provided fileSystemId. Parameters: fileSystemId: string Returns: Promise (Chrome 96+) chrome.fileSystemProvider.getAll(): Promise Returns all file systems mounted by the extension. Returns: Promise (Chrome 96+) chrome.fileSystemProvider.mount(options: MountOptions): Promise Mounts a file system with the specified fileSystemId and displayName. displayName will be shown in the Files app's sidebar. displayName can contain any character, including '/', but it cannot be an empty string. The displayName should be descriptive, but it does not have to be unique. fileSystemId cannot be an empty string. Depending on the type of file system being mounted, the source option must be set appropriately. In case of an error, runtime.lastError will be set to the appropriate error code. Parameters: options: MountOptions Returns: Promise (Chrome 96+) chrome.fileSystemProvider.notify(options: NotifyOptions): Promise Notifies about changes to a watched directory at observedPath in a recursive manner. If the file system is mounted with supportsNotifyTag, tag must be provided, and all changes since the last notification will always be reported, even if the system was turned off. The last tag can be retrieved using getAll. To use this option, the file_system_provider.notify manifest option must be set to true. The tag can be any string that is unique for each call, so that the last registered notification can be identified. For example, if the provider extension starts operating after a reboot, and the last registered notification tag is 123, it should call notify for all changes that happened since the change tagged as 123. It cannot be an empty string. Not all providers can provide a tag, but if the file system has a change log, the tag could be for example a change number or a version number. Note: If a parent directory is removed, all entries derived from it are removed as well, and if they are being watched, the API must be notified. Additionally, if a directory is renamed, all entries appearing in it will be removed, as they will no longer be valid in their original paths. In case of an error, runtime.lastError will be set to the appropriate error code. Parameters: options: NotifyOptions Returns: Promise (Chrome 96+) ``` -------------------------------- ### Chrome Tabs API - Example: Get Current Tab (Callback) Source: https://developer.chrome.com/docs/extensions/reference/api/tabs_hl=he Provides a callback-based approach to retrieve the currently active tab. This method is an alternative to the async/await pattern for getting the user's current tab. ```JavaScript function getCurrentTab(callback) { let queryOptions = { active: true, lastFocusedWindow: true }; chrome.tabs.query(queryOptions, ([tab]) => { if (chrome.runtime.lastError) console.error(chrome.runtime.lastError); // `tab` will either be a `tabs.Tab` instance or `undefined`. callback(tab); }); } ``` -------------------------------- ### Handle TTS Language Installation Request Source: https://developer.chrome.com/docs/extensions/reference/api/ttsEngine_hl=pl Called when a TTS client requests to install a new language. The engine should attempt to download and install the language, then call ttsEngine.updateLanguage with the result. Upon success, the engine should also call ttsEngine.updateVoices to register newly available voices. ```APIDOC chrome.ttsEngine.onInstallLanguageRequest.addListener(callback: function) Callback signature: (requestor: TtsClient, lang: string) => void Parameters: * requestor: TtsClient * lang: string ``` -------------------------------- ### Chrome Tabs API - Example: Get Current Tab (Async) Source: https://developer.chrome.com/docs/extensions/reference/api/tabs_hl=he Shows an asynchronous method to retrieve the currently active tab in the most recently focused window. This is useful for getting the user's current context. ```JavaScript async function getCurrentTab() { let queryOptions = { active: true, lastFocusedWindow: true }; // `tab` will either be a `tabs.Tab` instance or `undefined`. let [tab] = await chrome.tabs.query(queryOptions); return tab; } ``` -------------------------------- ### Check Alarm State on Service Worker Start Source: https://developer.chrome.com/docs/extensions/reference/api/alarms_hl=zh-cn This example demonstrates how to check the state of an alarm and create it if it doesn't exist, ensuring it's active when the service worker starts. ```javascript const STORAGE_KEY="user-preference-alarm-enabled"; async function checkAlarmState(){ const {alarmEnabled} = await chrome.storage.get(STORAGE_KEY); if (alarmEnabled) { const alarm = await chrome.alarms.get("my-alarm"); if (!alarm) { await chrome.alarms.create({periodInMinutes: 1}); } } } checkAlarmState(); ``` -------------------------------- ### Switching Between Side Panels Source: https://developer.chrome.com/docs/extensions/reference/api/sidePanel_hl=pl This example shows how to manage different side panel content. It sets an initial welcome page and then switches to a main side panel when the user navigates to a different tab. It utilizes `chrome.runtime.onInstalled`, `chrome.tabs.onActivated`, `chrome.sidePanel.setOptions`, and `chrome.sidePanel.getOptions`. ```javascript constwelcomePage='sidepanels/welcome-sp.html'; constmainPage='sidepanels/main-sp.html'; chrome.runtime.onInstalled.addListener(()=>{ chrome.sidePanel.setOptions({path:welcomePage}); chrome.sidePanel.setPanelBehavior({openPanelOnActionClick:true}); }); chrome.tabs.onActivated.addListener(async({tabId})=>{ const{path}=awaitchrome.sidePanel.getOptions({tabId}); if(path===welcomePage){ chrome.sidePanel.setOptions({path:mainPage}); } }); ``` -------------------------------- ### Get URL Source: https://developer.chrome.com/docs/extensions/reference/api/runtime_hl=tr Converts a relative path within an app/extension install directory to a fully qualified URL. The path parameter specifies the resource's path relative to the install directory. ```APIDOC chrome.runtime.getURL( path: string ): string ``` -------------------------------- ### Download Created Event Source: https://developer.chrome.com/docs/extensions/reference/api/downloads_hl=de Wird ausgelöst, wenn ein Download beginnt, mit dem DownloadItem-Objekt. ```APIDOC chrome.downloads.onCreated.addListener(callback: function): void Dieses Ereignis wird mit dem DownloadItem-Objekt ausgelöst, wenn ein Download beginnt. Parameter: * callback: function - Der Parameter callback sieht so aus: (downloadItem: DownloadItem) => void ``` -------------------------------- ### Example: Displaying a Popup Source: https://developer.chrome.com/docs/extensions/reference/api/action_hl=id This example demonstrates how to set and display a popup window when the extension's icon is clicked. It utilizes the `action.setPopup` and `action.onClicked` methods. ```javascript // In your background script (e.g., background.js) // Set the popup when the extension is installed or updated chrome.runtime.onInstalled.addListener(() => { chrome.action.setPopup({ popup: 'popup.html' }); }); // Optional: You can also set the popup when the icon is clicked if needed, // but setting it on install is more common. // chrome.action.onClicked.addListener((tab) => { // chrome.action.openPopup(); // }); // popup.html (example content) // // // // My Extension Popup // // //

Hello from my extension!

// // ``` -------------------------------- ### Handle Download Creation Source: https://developer.chrome.com/docs/extensions/reference/api/downloads_hl=th Fired with a DownloadItem object when a download begins. ```APIDOC chrome.downloads.onCreated.addListener(callback: function): void Callback parameters: - downloadItem: DownloadItem - The DownloadItem object for the new download. ``` -------------------------------- ### Get URL Source: https://developer.chrome.com/docs/extensions/reference/api/runtime_hl=bn Converts a relative path within an app/extension install directory to a fully qualified URL. The path parameter is a string representing the resource's path relative to the install directory. ```APIDOC chrome.runtime.getURL( path: string, ): string ``` -------------------------------- ### Scanner API - Examples Source: https://developer.chrome.com/docs/extensions/reference/api/documentScan_hl=fr Provides practical examples for using the Scanner API, such as retrieving a page as a blob, scanning a page, and displaying configuration. ```APIDOC Examples Retrieve a page as a blob Scan a page in Letter format Display configuration ``` -------------------------------- ### Handle TTS Language Status Requests Source: https://developer.chrome.com/docs/extensions/reference/api/ttsEngine_hl=ar Listens for requests from TTS clients to get the installation status of a specific language. ```JavaScript chrome.ttsEngine.onLanguageStatusRequest.addListener( callback: function(requestor: TtsClient, lang: string) => void ) ``` -------------------------------- ### Manifest Configuration for FileSystemProvider Source: https://developer.chrome.com/docs/extensions/reference/api/fileSystemProvider_hl=th Declares the 'fileSystemProvider' permission and configures capabilities for the File System Provider API in the extension's manifest.json. This includes settings for configurability, multiple mounts, watchability, and the data source. ```JSON { "name": "My extension", ... "permissions":[ "fileSystemProvider" ], ... "file_system_provider_capabilities":{ "configurable": true, "watchable": false, "multiple_mounts": true, "source": "network" }, ... } ``` -------------------------------- ### Get Extension URL Source: https://developer.chrome.com/docs/extensions/reference/api/runtime_hl=vi Converts a relative path within the extension's install directory to a fully qualified URL. ```javascript chrome.runtime.getURL( path: string ): string ``` -------------------------------- ### Get All Extensions Source: https://developer.chrome.com/docs/extensions/reference/api/management_hl=zh-cn Retrieves a list of information for all installed extensions and apps. ```APIDOC chrome.management.getAll(): Promise Returns a list of information about the installed extensions and apps. ``` -------------------------------- ### APIDOC: UrlFilter Examples Source: https://developer.chrome.com/docs/extensions/reference/api/declarativeContent_hl=zh-cn Provides examples of using UrlFilter conditions for matching web page URLs. ```APIDOC UrlFilter Conditions: hostSuffix: string Matches all URLs with the specified host suffix (e.g., 'google.com'). pathPrefix: string Matches URLs with the specified path prefix (e.g., '/docs/extensions'). urlContains: string Matches URLs that contain the specified substring (e.g., 'developer.chrome.com'). Note: All conditions are case-sensitive. ``` -------------------------------- ### Get Font List Source: https://developer.chrome.com/docs/extensions/reference/api/fontSettings_hl=id Retrieves a list of all available font names installed on the system. ```javascript chrome.fontSettings.getFontList(): Promise ``` -------------------------------- ### chrome.fileSystemProvider API Methods Source: https://developer.chrome.com/docs/extensions/reference/api/fileSystemProvider_hl=de Provides an overview of the core methods available in the chrome.fileSystemProvider API for managing file systems, including get, getAll, mount, notify, and unmount. ```APIDOC chrome.fileSystemProvider: get(): Returns the FileSystemInfo object for the specified file system. getAll(): Returns a list of all mounted FileSystemInfo objects. mount(options, callback): Mounts a file system with the given options. notify(options, callback): Notifies the system about changes to a file or directory. unmount(options, callback): Unmounts a file system. ``` -------------------------------- ### Open Extension Page in New Tab Source: https://developer.chrome.com/docs/extensions/reference/api/tabs_hl=it A common pattern for extensions is to open an onboarding page in a new tab when the extension is installed. This example demonstrates how to achieve that. No permissions are required for this specific functionality. ```javascript chrome.runtime.onInstalled.addListener(({reason})=>{ if(reason==='install'){ chrome.tabs.create({ url:"onboarding.html" }); } }); ``` -------------------------------- ### chrome.fileSystemProvider API Methods Source: https://developer.chrome.com/docs/extensions/reference/api/fileSystemProvider_hl=bn Provides methods for managing file systems: `get()` to retrieve a file system, `getAll()` to get all mounted file systems, `mount()` to mount a file system, `notify()` to notify of changes, and `unmount()` to unmount a file system. ```APIDOC chrome.fileSystemProvider.get(fileSystemId) chrome.fileSystemProvider.getAll() chrome.fileSystemProvider.mount(fileSystemId, options) chrome.fileSystemProvider.notify(fileSystemId, changes) chrome.fileSystemProvider.unmount(options) ``` -------------------------------- ### Service Worker Example: Declarative Content Source: https://developer.chrome.com/docs/extensions/reference/api/action_hl=fa This example demonstrates how a background script (service worker) can disable an extension's action by default and then use declarative content to enable it on specific websites (.example.com). It shows the setup of rules using `chrome.declarativeContent.onPageChanged`. ```JavaScript // service-worker.js // Wrap in an onInstalled callback to avoid unnecessary work // every time the service worker is run chrome.runtime.onInstalled.addListener(()=>{ // Page actions are disabled by default and enabled on select tabs chrome.action.disable(); // Clear all rules to ensure only our expected rules are set chrome.declarativeContent.onPageChanged.removeRules(undefined,()=>{ // Declare a rule to enable the action on example.com pages let exampleRule={ conditions:[ new chrome.declarativeContent.PageStateMatcher({ pageUrl:{hostSuffix:'.example.com'}, }) ], actions:[new chrome.declarativeContent.ShowAction()], }; // Finally, apply our new array of rules let rules=[exampleRule]; chrome.declarativeContent.onPageChanged.addRules(rules); }); }); ``` -------------------------------- ### Set Wallpaper Example Source: https://developer.chrome.com/docs/extensions/reference/api/wallpaper_hl=bn Demonstrates how to set a wallpaper using a URL with specific layout and filename. This function is available in Chrome 43+. ```JavaScript chrome.wallpaper.setWallpaper({ 'url':'https://example.com/a_file.jpg', 'layout':'CENTER_CROPPED', 'filename':'test_wallpaper' }, function(){} ); ```