YouTube increase volume via js?

Viewed 31

I want to increase the volume of a youtube video (directly on youtube.com, not an iframe) with some js. I have tried:

function volumeup() { let evt = new KeyboardEvent('keydown', { shiftKey: false, key: 'ArrowUp', keyCode: 38 }); document.dispatchEvent(evt); }

But it doesn't seem to work. And since the youtube volume slider is not a 'real' slider, ...

<div class="ytp-volume-slider" style="touch-action: none;">
<div class="ytp-volume-slider-handle" style="left: 21.55px;">
</div></div>

... I have no clue how to control it else.

Kind regards.

1 Answers

try this

document.querySelector('.ytd-watch-flexy .html5-main-video').volume += 0.1

Note! this selector can be changed, so it can be a good idea loop over all video elements in page.

Related