Widevine is a pain.
I used the Castlabs Electron fork for ECS located here.
- Most services will NOT work when you play actual content if you just run the code
- You must build a package signed by Widevine for it to work properly
I used the Castlabs EVS for this located here.
- You must add a call in the build process to EVS via the electron-builder afterPack or afterSign hook
- You must sign prior to code signing on Mac and after code signing on Windows
Something like this for mac (named afterPack.js
and referenced in afterPack in your package.json
build key):
exports.default = function (context) {
// Skip if not mac
if (process.platform !== 'darwin') return
// VMP sign via EVS
const { execSync } = require('child_process')
console.log('VMP signing start')
execSync('python3 -m castlabs_evs.vmp sign-pkg ./dist/mac ' + context.appOutDir)
console.log('VMP signing complete')
}
NOTE: You must sign up for an EVS account (free) and you will need to have Python to use it.
In your main.js instantiate your window when Widevine is ready (read guide for the appropriate setup):
// Widevine DRM setup
app.commandLine.appendSwitch('no-verify-widevine-cdm')
const isOffline = false
const widevineDir = app.getPath('userData')
// Widevine DRM ready
app.on('widevine-ready', () => {
createWindow()
})
On the browser support part of this, be sure to set a valid user agent e.g. (mac):
[BrowserWindow or BrowserView].webContents.loadURL('https://urltostream', { userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36' })
I have a working app located here.