Electron 使用Pepper Flash插件
Electron 中支持 Pepper Flash 插件的使用。想要在 Electron 里面使用 Pepper Flash 插件,我們需要手動(dòng)設(shè)置 Pepper Flash 的路徑,并且在應(yīng)用程序中啟用 Pepper Flash。
保留一份 Flash 插件的副本
在 macOS 和 Linux 上,我們可以在 Chrome 瀏覽器的 chrome://plugins 頁(yè)面上找到 Pepper Flash 的插件信息。插件的路徑和版本會(huì)對(duì) Election 對(duì)其的支持有幫助。你也可以把插件復(fù)制到另一個(gè)路徑以保留一份副本。
添加插件在 Electron 里的開(kāi)關(guān)
我們可以直接在命令行中用 --ppapi-flash-path 和 ppapi-flash-version 或者在 app 的準(zhǔn)備事件前調(diào)用
app.commandLine.appendSwitch 這個(gè)方法。同時(shí)添加 browser-window 的插件開(kāi)關(guān)。例如:
- const { app, BrowserWindow } = require('electron')
- const path = require('path')
- // 指定flash路徑,假定它與main.js放在同一目錄中。
- let pluginName
- switch (process.platform) {
- case 'win32':
- pluginName = 'pepflashplayer.dll'
- break
- case 'darwin':
- pluginName = 'PepperFlashPlayer.plugin'
- break
- case 'linux':
- pluginName = 'libpepflashplayer.so'
- break
- }
- app.commandLine.appendSwitch('ppapi-flash-path', path.join(__dirname, pluginName))
- // 可選:指定flash的版本,例如v17.0.0.169
- app.commandLine.appendSwitch('ppapi-flash-version', '17.0.0.169')
- app.on('ready', () => {
- let win = new BrowserWindow({
- width: 800,
- height: 600,
- webPreferences: {
- plugins: true
- }
- })
- win.loadURL(`file://${__dirname}/index.html`)
- // ...
- })
或者也可以嘗試加載系統(tǒng)安裝的 Pepper Flash 插件,而不是裝運(yùn) 插件,其路徑可以通過(guò)調(diào)用 app.getPath('pepperFlashSystemPlugin') 獲取。
使用webview標(biāo)簽啟用插件
在<webview>標(biāo)簽里添加 plugins 屬性。例如下面所示:
<webview src="http://www.adobe.com/software/flash/about/" plugins></webview>
故障排查
我們可以通過(guò)在控制臺(tái)打印 navigator.plugins 來(lái)檢查 Pepper Flash 插件是否加載 。
Pepper Flash 插件的操作系統(tǒng)必須和 Electron 的操作系統(tǒng)匹配。在 Windows 中, 一個(gè)常見(jiàn)的錯(cuò)誤是對(duì) 64 位版本的 Electron 使用 32bit 版本的 Flash 插件。
在 Windows 中,傳遞給 --ppapi-flash-path 的路徑必須使用 `` 作為路徑分隔符,使用 POSIX-style 的路徑將無(wú)法工作。
對(duì)于一些操作,例如使用 RTMP 的流媒體,有必要向播放器的 .swf 文件授予更多的權(quán)限。 實(shí)現(xiàn)這一點(diǎn)的一種方式是使用 nw-flash-trust。






















