Class: Extensions
Class: Extensions
Load and interact with extensions.
Process: Main
This class is not exported from the 'electron'
module. Elle n'est disponible qu'en tant que valeur de retour des autres méthodes dans l'API Electron.
Instances of the Extensions
class are accessed by using extensions
property of
a Session
.
Événements d’instance
The following events are available on instances of Extensions
:
Événement : 'extension-loaded'
Retourne :
event
Eventextension
Extension
Émis après le chargement d’une extension. Cela se produit chaque fois qu’une extension ajoutée à l’ensemble d’extensions « activées ». Ceci comprend :
- Extensions being loaded from
Extensions.loadExtension
. - Extensions rechargées :
- à partir d'un plantage.
- if the extension requested it (
chrome.runtime.reload()
).
Événement : 'extension-unloaded'
Retourne :
event
Eventextension
Extension
Émis après le déchargement d’une extension. This occurs when
Session.removeExtension
is called.
Événement : 'extension-ready'
Retourne :
event
Eventextension
Extension
Émis après le chargement d’une extension et l’initialisation de tout l’état du navigateur nécessaire pour prendre en charge le démarrage de la page d’arrière-plan de l’extension.
Méthodes d’instance
The following methods are available on instances of Extensions
:
extensions.loadExtension(path[, options])
path
string - Path to a directory containing an unpacked Chrome extension
Returns Promise<Extension>
- resolves when the extension is loaded.
Cette méthode déclenche une exception si l’extension n’a pas pu être chargée. Si il y a des avertissements lors de l'installation de l'extension (par ex. si l'extension utilise une API non prise en charge par Electron) ceux-ci seront enregistrés dans la console.
Notez qu'Electron ne prend pas en charge la gamme complète des API d'extensions Chrome. See Supported Extensions APIs for more details on what is supported.
Notez que dans les versions précédentes d'Electron, les extensions qui avaient été chargées etaient mémorisées pour les exécutions futures de l'application. This is no longer the case:
loadExtension
must be called on every boot of your app if you want the
extension to be loaded.
const { app, session } = require('electron')
const path = require('node:path')
app.whenReady().then(async () => {
await session.defaultSession.extensions.loadExtension(
path.join(__dirname, 'react-devtools'),
// allowFileAccess is required to load the devtools extension on file:// URLs.
{ allowFileAccess: true }
)
// Note that in order to use the React DevTools extension, you'll need to
// download and unzip a copy of the extension.
})
Cette API ne supporte pas le chargement des extensions compressées (.crx).
Note: This API cannot be called before the ready
event of the app
module
is emitted.
Note: Loading extensions into in-memory (non-persistent) sessions is not supported and will throw an error.
extensions.removeExtension(extensionId)
extensionId
string - ID of extension to remove
Décharge une extension.
Note: This API cannot be called before the ready
event of the app
module
is emitted.
extensions.getExtension(extensionId)
extensionId
string - ID of extension to query
Returns Extension | null
- The loaded extension with the given ID.
Note: This API cannot be called before the ready
event of the app
module
is emitted.
extensions.getAllExtensions()
Returns Extension[]
- A list of all loaded extensions.
Note: This API cannot be called before the ready
event of the app
module
is emitted.