Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Electron uses the Widevine CDM plug-in


May 25, 2021 Electron


Table of contents


At Electron, you can use the Widevine CDM plug-in to mount Chrome.

Get the plug-in

Electron does not license the Widevine CDM plug-in, and in order to get it, you first need to install an official chrome browser, which matches the chrome version used by the architecture and Electron build.

Note: The major version of Chrome must be the same as the version used by Electron, otherwise the plug-in will not navigator.plugins have installed it .

Windows & OS X

Open chrome://components/ find WidevineCdm it's updated to the latest version, and then you can find all plug-in binary files from APP_DATA/Google/Chrome/WidevineCDM/VERSION/_platform_specific/PLATFORM_ARCH/

APP_DATA where the system stores data, it's %LOCALAPPDATA% and it's the ~/Library/Application Support VERSION is a version string for theWidevine CDM plug-in, 1.4.8.866 . PLATFORM is mac or win . ARCH is x86 or x64 .

In Windows, the necessary binary files are widevinecdm.dll and widevinecdmadapter.dll and in OS X, they are libwidevinecdm.dylib and widevinecdmadapter.plugin . You can copy them where you like, but they have to be put together.

Linux

In Linux, Chrome loads plug-in binary files together, which you can find under /opt/google/chrome with libwidevinecdm.so names libwidevinecdm.so libwidevinecdmadapter.so .

Use plug-ins

After obtaining the --widevine-cdm-path command line switch to pass widevinecdmadapter to Electron, and the --widevine-cdm-version switch.

Note: Although widevinecdmadapter binary files are passed to Electron, widevinecdm binary should be placed next to it.

app must be ready event of the app module is triggered, and the plug-in used by page must be activated.

Example code:

// You have to pass the filename of `widevinecdmadapter` here, it is
// * `widevinecdmadapter.plugin` on OS X,
// * `libwidevinecdmadapter.so` on Linux,
// * `widevinecdmadapter.dll` on Windows.
app.commandLine.appendSwitch('widevine-cdm-path', '/path/to/widevinecdmadapter.plugin');
// The version of plugin can be got from `chrome://plugins` page in Chrome.
app.commandLine.appendSwitch('widevine-cdm-version', '1.4.8.866');

var mainWindow = null;
app.on('ready', function() {
  mainWindow = new BrowserWindow({
    webPreferences: {
      // The `plugins` have to be enabled.
      plugins: true
    }
  })
});

Verify the plug-in

To verify that the plug-in works, you can use the following method:

  • Open the developer tool to see navigator.plugins contain the WidevineCDM plug-in.
  • Open https://shaka-player-demo.appspot.com/ load a Widevine
  • Open http://www.dash-player.com/demo/drm-test-area/, check if the interface bitdash uses Widevine in your browser and then play video.