Class: Extensions
Class: Extensions
Load and interact with extensions.
Process: Main
_This class is not exported from the 'electron'
module. Electron API の他のメソッドの戻り値としてのみ利用できます。
Instances of the Extensions
class are accessed by using extensions
property of
a Session
.
インスタンスイベント
The following events are available on instances of Extensions
:
イベント: 'extension-loaded'
戻り値:
event
Eventextension
Extension
拡張機能が読み込まれた後に発生します。 これは、拡張機能が "有効な" 拡張機能のセットに追加されるたびに発生します。 これは以下のものが含まれます。
- Extensions being loaded from
Extensions.loadExtension
. - 拡張機能が再読み込みされるとき。
- クラッシュによって。
- if the extension requested it (
chrome.runtime.reload()
).
イベント: 'extension-unloaded'
戻り値:
event
Eventextension
Extension
拡張機能が取り除かれた後に発生します。 This occurs when
Session.removeExtension
is called.
イベント: 'extension-ready'
戻り値:
event
Eventextension
Extension
拡張機能が読み込まれ、必要なブラウザの状態がすべて初期化され、拡張機能のバックグラウンドページの開始をサポートするようになった後に発生します。
インスタンスメソッド
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.
このメソッドは、拡張機能を読み込めなかった場合に例外を発生させます。 拡張機能のインストール時に警告が発生した場合 (Electron が未サポートの API を拡張機能が要求した場合など) は、コンソールにログが記録されます。
注意として、Electron は Chrome 拡張機能の API のすべてをサポートしていません。 See Supported Extensions APIs for more details on what is supported.
注意として、以前のバージョンの Electron では、読み込まれた拡張機能は以降のアプリケーション実行のために記憶されます。 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.
})
この API は、パッケージした (.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
拡張機能を取り除きます。
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.