Table of Contents Previous entry (api:GM_cookie.delete) Next entry (api:window.onurlchange)
Sets the mute state of the current tab.
Parameters
true to mute the tab, false to un‑mute it.undefined.Return value
Promise<void> that resolves on success and rejects with an error string on failure.Example (callback)
// ==UserScript==
...
// @grant GM_audio
// ==/UserScript==
GM_audio.setMute({ isMuted: true }, function(err) {
if (err) console.error('mute failed:', err);
else console.log('tab muted');
});
Example (Promise)
// ==UserScript==
...
// @grant GM.audio
// ==/UserScript==
await GM.audio.setMute({ isMuted: false });
console.log('tab un‑muted');
Retrieves the current audio state of the tab.
Parameters
user – User action (e.g., mute button).capture – Tab capture API call.extension – Extension call.Return value
Promise that resolves with the callback’s info object on success or rejects on error.Example (callback)
// ==UserScript==
...
// @grant GM_audio
// ==/UserScript==
GM_audio.getState(function(state) {
if (!state) return console.error('failed to read state');
console.log('muted?', state.isMuted, 'reason:', state.muteReason);
console.log('audible?', state.isAudible);
});
Example (Promise)
// ==UserScript==
...
// @grant GM.audio
// ==/UserScript==
const state = await GM.audio.getState();
console.log(`muted=${state.isMuted} (reason=${state.muteReason}) audible=${state.isAudible}`);
Registers a listener that is called whenever the tab’s mute or audible state changes.
Parameters
false if not muted.undefined otherwise.Return value
Promise<void> that resolves when the listener has been successfully registered.Example (callback)
// ==UserScript==
...
// @grant GM_audio
// ==/UserScript==
GM_audio.addStateChangeListener(function(e) {
if ('muted' in e) console.log('muted:', e.muted);
if ('audible' in e) console.log('audible:', e.audible);
});
Example (Promise)
// ==UserScript==
...
// @grant GM.audio
// ==/UserScript==
await GM.audio.addStateChangeListener(ev => {
if (ev.muted) console.log('muted by', ev.muted);
});
Unregisters a previously added state‑change listener.
Parameters
addStateChangeListener:Return value
Promise<void> that resolves when the listener has been removed.Example (callback)
// ==UserScript==
...
// @grant GM_audio
// ==/UserScript==
function onAudio(ev) { console.log(ev); }
GM_audio.addStateChangeListener(onAudio);
...
GM_audio.removeStateChangeListener(onAudio, () => console.log('listener removed'));
Example (Promise)
// ==UserScript==
...
// @grant GM.audio
// ==/UserScript==
await GM.audio.removeStateChangeListener(onAudio);
console.log('listener removed');