Skip to content

Instantly share code, notes, and snippets.

@DavidBuchanan314
Last active September 24, 2023 04:57
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save DavidBuchanan314/4ba4cf1018c616b33bc2d3c8b68ddb84 to your computer and use it in GitHub Desktop.
Save DavidBuchanan314/4ba4cf1018c616b33bc2d3c8b68ddb84 to your computer and use it in GitHub Desktop.
Context: https://github.com/AsahiLinux/docs/issues/63#issuecomment-1455373735 Tested with TamperMonkey in Firefox
// ==UserScript==
// @name Fake Widevine
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Fake the presence of a functional Widevine CDM - enough to get the spotify UI to launch, so you can pick another playback device.
// @author David Buchanan
// @match https://open.spotify.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=spotify.com
// @grant none
// ==/UserScript==
(window => {
'use strict';
function MediaKeySession() {
this.sessionId = "";
}
function MediaKeys() {
this.autoId = "MediaKeys_1";
};
MediaKeys.prototype.createSession = () => {
return new Promise((resolve, reject) => {
resolve(new MediaKeySession());
});
};
function MediaKeySystemAccess(config) {
this.name = "com.widevine.alpha";
this.keySystem = "com.widevine.alpha";
this.autoId = "MediaKeySystemAccess_1";
this.config = config;
};
MediaKeySystemAccess.prototype.createMediaKeys = () => {
//console.log("it's happening!");
return new Promise((resolve, reject) => {
resolve(new MediaKeys());
});
};
MediaKeySystemAccess.prototype.getConfiguration = () => {
return new Promise((resolve, reject) => {
resolve(this.config);
});
};
window.navigator.requestMediaKeySystemAccess = (keySystem, supportedConfigurations) => {
//console.log("hooked!");
return new Promise((resolve, reject) => {
if (keySystem !== "com.widevine.alpha") {
reject("Unsupported keySystem or supportedConfiguration");
}
resolve(new MediaKeySystemAccess(supportedConfigurations));
});
};
})(window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment