From: Kohei Yoshino Date: Fri, 8 Mar 2019 16:31:47 +0000 (-0500) Subject: Bug 1391439 - Add ability to capture and attach a screenshot through the Bugzilla UI X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4329b75eaf20f8b5796a9b11ba0ae40557a94ddf;p=thirdparty%2Fbugzilla.git Bug 1391439 - Add ability to capture and attach a screenshot through the Bugzilla UI --- diff --git a/js/attachment.js b/js/attachment.js index 184945501..4721c21c9 100644 --- a/js/attachment.js +++ b/js/attachment.js @@ -301,6 +301,7 @@ Bugzilla.AttachmentForm = class AttachmentForm { this.$filename = document.querySelector('#att-filename'); this.$dropbox = document.querySelector('#att-dropbox'); this.$browse_label = document.querySelector('#att-browse-label'); + this.$capture_label = document.querySelector('#att-capture-label'); this.$textarea = document.querySelector('#att-textarea'); this.$preview = document.querySelector('#att-preview'); this.$preview_name = this.$preview.querySelector('[itemprop="name"]'); @@ -326,6 +327,7 @@ Bugzilla.AttachmentForm = class AttachmentForm { this.$dropbox.addEventListener('dragend', () => this.dropbox_ondragend()); this.$dropbox.addEventListener('drop', event => this.dropbox_ondrop(event)); this.$browse_label.addEventListener('click', () => this.$file.click()); + this.$capture_label.addEventListener('click', () => this.capture_onclick()); this.$textarea.addEventListener('input', () => this.textarea_oninput()); this.$textarea.addEventListener('paste', event => this.textarea_onpaste(event)); this.$remove_button.addEventListener('click', () => this.remove_button_onclick()); @@ -561,6 +563,50 @@ Bugzilla.AttachmentForm = class AttachmentForm { } } + /** + * Called whenever the Take a Screenshot button is clicked. Capture a screen, window or browser tab if the Screen + * Capture API is supported, then attach it as a PNG image. + * @see https://developer.mozilla.org/en-US/docs/Web/API/Screen_Capture_API + */ + capture_onclick() { + if (typeof navigator.mediaDevices.getDisplayMedia !== 'function') { + alert('This function requires the most recent browser version such as Firefox 66 or Chrome 72.'); + return; + } + + const $video = document.createElement('video'); + const $canvas = document.createElement('canvas'); + + navigator.mediaDevices.getDisplayMedia({ video: { displaySurface: 'window' } }).then(stream => { + // Render a captured screenshot on `