69

Google Chrome is now shipping with a download button for videos that are just embedded videos (i.e. not MSE):

Canary Controls

I'm having a hard time find any documentation for Chrome's implementation of the <video> tag. Does anyone know if there is a way - short of disabling "controls" and creating your own video player controls - of disabling this feature?

I realize that if this is showing, it's already easy to download the video, I just want to disable that functionality from appearing as part of the controls.

Thank you!

ranvel
  • 861
  • 1
  • 14
  • 19
  • Possible duplicate of [In Chrome 55, prevent showing Download button for HTML 5 video](https://stackoverflow.com/questions/41115801/in-chrome-55-prevent-showing-download-button-for-html-5-video) – brichins Nov 01 '17 at 21:37
  • This question was asked first and is referenced in the answer to that question. That is the duplicate of this question. – ranvel Nov 02 '17 at 00:31
  • Yes, I'm aware - but it is [standard practice](https://meta.stackoverflow.com/a/252017/957950) to pick the question and/or answers with the most votes as the one to leave open. – brichins Nov 02 '17 at 17:06
  • This one had objectively better question which specifies the type of video, with objectively better answer, which refers to the documentation (and not another question) and my question had the most upvotes as of December, when the other asker duplicated this one and then "found" the response. – ranvel Nov 02 '17 at 17:13
  • The point of linking/merging 'duplicate' questions is discoverability and usefulness for the larger community going forward. [Priority](https://en.wikipedia.org/wiki/Priority_right) and [rep](https://meta.stackexchange.com/q/158853/174739) really aren't that important, but feel free to flag the other one as a duplicate of yours or request that they be merged. – brichins Nov 02 '17 at 17:49
  • 3
    I, like seven others, since just days after that question was published have already flagged that question as a duplicate. It was allowed to grow because nothing was done about it. The "duplicate question" reads like "This user didn't do his/her homework" and is not inspiring for future efforts on the platform when assigned to the actual original question. – ranvel Nov 02 '17 at 17:55
  • Is it possible to modify the downloaded file name?[How to set the download file extension for blob data](https://stackoverflow.com/q/71686536/6521116) – LF00 Apr 07 '22 at 06:03

11 Answers11

94

or you can simply add nodownload in controlsList

<video width="512" height="380" controls controlsList="nodownload">
    <source data-src="mov_bbb.ogg" type="video/mp4">
</video>
Elyor
  • 5,396
  • 8
  • 48
  • 76
  • 3
    As of version 58 of Chrome, this functionality provides the best solution. – ranvel Apr 24 '17 at 17:49
  • 1
    This does not work on Android devices. Any Suggestions to do the same for android devices? Thanks – Ajit Balachandran Feb 19 '18 at 05:29
  • This answer had no effect at all on my samsung J3. – Thaps Oct 17 '18 at 14:51
  • plain javascript – Simon Berton Apr 25 '19 at 18:36
  • Is it possible to modify the downloaded file name?[How to set the download file extension for blob data](https://stackoverflow.com/q/71686536/6521116) – LF00 Apr 07 '22 at 06:03
55

You can inspect the controls of the native Chrome Video Player by activating the shadow DOM in Settings|Preferences -> Elements -> Show user agent shadow DOM

shadow dom

After that you can inspect the players buttons.

Player DOM

Now the problem is that the download button cannot be accessed via CSS for some reason.

video::-internal-media-controls-download-button {
    display:none;
}

won't work. Even selecting the preceding button and targeting its neighbor using + or ~ won't work.

The only way we found yet was nudging the button out of the viewable area by giving the control panel a greater width and making the enclosure overflow: hidden

video::-webkit-media-controls {
    overflow: hidden !important
}
video::-webkit-media-controls-enclosure {
    width: calc(100% + 32px);
    margin-left: auto;
}

I hope google will fix this issue soon because most content providers won't be happy with this...

nana
  • 4,426
  • 1
  • 34
  • 48
Demnogonis
  • 3,172
  • 5
  • 31
  • 45
  • 3
    This is super useful and gives me some ideas for work arounds - I didn't know about being able to expose the Chrome UI as a Shadow DOM. Content providers don't have to worry about this since it only happens when you are accessing the .webm directly. Responsible people or people with resources to transcode MSE-Dash files are safe - the download icon is unavailable. My guess is that this is a nudge from Google to get people to encode using adaptive video. – ranvel Dec 06 '16 at 00:26
  • 1
    Yes you're right but MSE-Dash requires a lot more server performance and cannot be played on iOS Safari. This is (unfortunately) a key requirement of our service. – Demnogonis Dec 06 '16 at 09:03
  • 1
    Am I the only one who has problem with this? My styles doesn't affect at fullscreen mode and download button is still there. – Jax-p Feb 02 '17 at 11:16
  • @JaxCze What does your CSS look like? Can you provide a fiddle? – Demnogonis Feb 02 '17 at 11:27
  • @Demnogonis just copied your source code. video::-webkit-media-controls-enclosure Affetcs well, so i just moved my button out of screen :D. But in devtools I don't see any affected styles for buttons. – Jax-p Feb 02 '17 at 11:44
  • This fix doesn't affect the button directly, because you can't target it with CSS. It works by making the controls a bit wider and nudging the button out of the view by applying overflow hidden to the parent. Is it Possible that your video also has that streaming button that jonalvarezz mentioned? – Demnogonis Feb 02 '17 at 12:05
  • https://m.youtube.com somehow is able to set "display:none" on the download button. I dont know if there is an api for this, or youtube is using some internal api to do this, but if youtube can do it, we should be allowed to do it as well. Anyone wants to take a dig at what youtube could be doing? – codneto Feb 28 '17 at 00:25
  • @codneto That's because youtube delivers their videos as blob/MSE-Dash. As discussed earlier the downloadbutton only appears if the file is directly referenced in the source. For example `` – Demnogonis Feb 28 '17 at 00:48
  • This solution is working for normal video. But for full screen, it is not working for me for some reason. – Alok Rajasukumaran Feb 14 '19 at 10:05
15

Demmongonis solution does work but be aware it can lead to unwanted results.

Android/Chrome sometimes, depends in the video I guess and other factors, adds buttons at the right of the download-button. i.e. the casting-button (there is no way to select it). It will make the download-button to remain visible and the last button to get hidden (casting-button)

casting button in Android 4.4 Chrome 55

Update

It is posible now to hide the download button using the controlsList attribute:

<video controlsList="nodownload" ... />
Alex M
  • 2,756
  • 7
  • 29
  • 35
jonalvarezz
  • 739
  • 6
  • 4
  • 2
    I guess the best way to tackle these issues is to hide the default controls and build a custom overlay alltogether... – Demnogonis Dec 20 '16 at 11:34
  • Agreed work in my case – Yasir Shabbir Choudhary Dec 04 '17 at 08:50
  • While the controlList does get rid of the download button. It doesn't stop the right click Save File As choice. – gwardell Nov 19 '18 at 09:56
  • Yes, for Chrome 58+, to hide the Download button, use ` – fuweichin Mar 30 '22 at 07:11
12

Yes, this is possible now, at least at the time of writing, you can use the controlsList attribute:

<video controls controlsList="nodownload">
  <source data-src="movie.mp4">
</video>

It seems this was introduced in Chrome 58, and the documentation for it is found here: https://developers.google.com/web/updates/2017/03/chrome-58-media-updates#controlslist

Developers can now customize media controls such as the download, fullscreen and remoteplayback buttons. Usage in HTML:

<video controls controlsList="nofullscreen nodownload noremote foobar"></video>

There is even an official sample page: https://googlechrome.github.io/samples/media/controlslist.html

bg17aw
  • 2,818
  • 1
  • 21
  • 27
3

One more control item I was trying to disable, additionally to 'download' - is 'picture-in-picture'.

Sadly there`s no property, for that purpose to be added in the controlsList. But there is an attribute - disablePictureInPicture you can add to the Element to disable pip.

Example disabling both download and picture-in-picture:

<video disablepictureinpicture controlslist="nodownload">...</video>

Details: https://wicg.github.io/picture-in-picture/#disable-pip

Andrii Bogachenko
  • 1,225
  • 13
  • 20
  • 1
    This is great! Hiding downloads was easy to find but not this one specifically which was giving me trouble with one page applications. – Jason Dec 12 '18 at 00:02
1

Hey I found a permanent solution that should work in every case!

For normal webdevelopment

<script type="text/javascript"> 
$("video").each(function(){jQuery(this).append('controlsList="nodownload"')}); 
</script>

HTML5 videos that has preload on false

$( document ).ready(function() {
  $("video").each(function(){
    $(this).attr('controlsList','nodownload');
    $(this).load();
  });
});

$ undevinded? --> Debug modus!

<script type="text/javascript"> 
jQuery("video").each(function(){jQuery(this).append('controlsList="nodownload"')}); 
</script>

HTML5 videos that has preload on false

jQuery( document ).ready(function() {
  jQuery("video").each(function(){
    jQuery(this).attr('controlsList','nodownload');
    jQuery(this).load();
  });
});

Let me know if it helped you out!

Chris Kroon
  • 109
  • 1
  • 5
  • 2
    Gosh, can it be done with any more jQuery functionality? – Endless Jun 03 '17 at 21:13
  • In my case it wasn't possible with any other solutions found on the internet... Sometimes you need some extra juice to get it running! Don't forget you probably only need 1 of the 4 scripts. – Chris Kroon Jun 12 '17 at 13:59
  • 1
    fyi, you don't have to loop over each video, and you are doing it wrong by using `append` instead of `attr`, it's enough to do: `jQuery('video').attr('controlsList, 'nodownload')` ` – Endless Jun 12 '17 at 14:17
  • You have when you got more then one video. And attr(ect) didn't seem to work (strange hu!..) – Chris Kroon Jun 13 '17 at 16:06
1

To keep it simple.. You need to add an attribute called controlslist (LOWERCASE, directly after controls) and you need to set its value to ="nodownload". Also, make sure your src file(type) and your attribute type's value match, unlike some of the above examples; my link is to a file named 'sunrise over water.mp4' on my Google Drive. How I do it looks like this:

<video src="https://drive.google.com/open?id=0B1CDu1eNPJqDVEQxMzZUV1dURjg" title="sunrise over water" width="420" height="300" controls controlslist="nodownload" type="video/mp4"> Video Not Supported By Your Browser... </video>

OR

<video width="440" height="320" title="sunrise over water" controls controlslist="nodownload"> <source src="https://drive.google.com/open?id=0B1CDu1eNPJqDVEQxMzZUV1dURjg" type="video/mp4"> Video Could Not Be Played In Your Browser... Sorry. </video>

1

In addition to above answers you have to add following code to disable context menu:

index.html: (globally)

<body oncontextmenu="return false;">

OR you can disable context menu for some element:

element.oncontextmenu = function (e) {
    e.preventDefault();
};
Ukr
  • 2,411
  • 18
  • 16
1

Plain javascript to disable the "download" Button from a video in your page:

<script>
    window.onload = function() {
        video = document.querySelector('video');
        if (video) {
           video.setAttribute("controlsList", "nodownload");
        }
    };
</script>

If you want to, you can also is querySelectorAll and remove each video. In my example I just have only one video per page.

Simon Berton
  • 468
  • 5
  • 13
0

The above answer offers a good solution. However, when I was working on this in my project, there were two problems with it.

  1. Download occurs (as if the download button had been pressed) when right margin area of the fullscreen button is touched on Android (mobile or tablet). Applying z-index didn't fix it.

  2. Because of overflow:hidden, the download button is invisible but still exists to the right of the fullscreen button. That means when you press "tab" several times after clicking any control button or bar on PC, you can still reach the download button.

Additionally, be careful -- some small-width devices (e.g. mobile phones) are small enough to hide the seek bar. It would need many more pixels to hide the download button.

I hope Google provides the option to adjust this ASAP.

pillravi
  • 4,035
  • 5
  • 19
  • 33
Meow Kim
  • 445
  • 4
  • 14
0

I using following JavaScript snippet which is working very well:

document.querySelectorAll("video[id^=media-player]").forEach((elem) => elem.controlsList.add("nodownload"));

Example: www.ring-cafe-finsterwalde.de/archiv/archiv.html#archiv4