Edge API

This section details the API for interacting with the Microsoft Edge browser features and capabilities. This API allows developers to extend and integrate with Edge's functionalities in a secure and controlled manner.

Introduction

The Edge API provides access to various browser features, enabling richer web applications and extensions. It is designed with security and performance in mind, adhering to modern web standards and best practices.

Note: Access to certain Edge API features may require specific permissions declared in your web application's manifest or through user consent.

Key Features

API Reference

edge.tabs

Provides methods for managing browser tabs.

Methods:

Method Description Parameters Returns
edge.tabs.create(options) Creates a new tab. options (object)
- url (string, optional): The URL to load in the new tab.
- active (boolean, optional): Whether the new tab should be active.
Promise<Tab>
edge.tabs.query(queryInfo) Gets information about one or more tabs. queryInfo (object)
- active (boolean, optional): Whether the tab is active.
- url (string | RegExp, optional): The URL of the tab.
Promise<Array<Tab>>
edge.tabs.update(tabId, updateProperties) Updates the properties of a tab. tabId (number)
updateProperties (object)
- url (string, optional): The new URL to navigate to.
- active (boolean, optional): Whether to make the tab active.
Promise<Tab>
edge.tabs.remove(tabId) Closes one or more tabs. tabId (number | Array<number>) Promise<void>

Tab Object:

Represents a browser tab.

edge.windows

Provides methods for managing browser windows.

Methods:

Method Description Parameters Returns
edge.windows.create(options) Creates a new browser window. options (object, optional)
- url (string, optional): The URL to load in the first tab.
- focused (boolean, optional): Whether the new window should be focused.
Promise<Window>
edge.windows.getCurrent(options) Gets the current window. options (object, optional)
- populate (boolean, optional): Whether to include tabs in the returned Window object.
Promise<Window>

Window Object:

Represents a browser window.

Permissions

To use the Edge API, you may need to declare permissions in your web application's manifest. The specific permissions depend on the features you intend to use.

{
  "manifest_version": 3,
  "name": "My Edge Extension",
  "version": "1.0",
  "permissions": [
    "tabs",
    "windows",
    "activeTab"
  ],
  "action": {
    "default_popup": "popup.html"
  }
}

Examples

Creating a new tab:

edge.tabs.create({ url: "https://example.com", active: true }).then(tab => {
    console.log(`New tab created with ID: ${tab.id}`);
});

Getting all active tabs:

edge.tabs.query({ active: true }).then(tabs => {
    tabs.forEach(tab => {
        console.log(`Active tab: ${tab.title} (${tab.url})`);
    });
});
Security Alert: Always validate user input and be mindful of potential security vulnerabilities when interacting with browser APIs. Ensure you only request necessary permissions.