DEV Community

ColonelParrot
ColonelParrot

Posted on

How to make Google's "Report issue" feedback form

Do you want to make your own feedback form with screenshot taking & screenshot editing functionality?

Google's feedback form:
Google Feedback Form

Let's make one just like Google's


Luckily for you, there's a library built already for this purpose. Introducing, FeedbackPlus.

GitHub logo ColonelParrot / feedbackplus

orked from puffinsoft/feedbackplus for backwards CDN compatibility.






FeedbackPlus is an open source Javascript library that allows you to add screenshot taking & screenshot editing functionality to your feedback forms

Available for use by cdn or via npm

The project is inspired by Google's report an issue widget, which allows you to take & edit screenshots. Under the hood, it uses the browser display API and fallbacks to html2canvas if available (see here)

Preview (demo)














Taking a Screenshot Editing screenshot

(click images to enlarge)

Quickstart

For more detailed instructions, see the documentation

You can find bare-minimum demo code for screenshotting & screenshot editing in the demo/simple folder

Import

npm:

$ npm i feedbackplus
import FeedbackPlus from 'feedbackplus'
Enter fullscreen mode Exit fullscreen mode

cdn via jsDelivr (or with cdnjs):

<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/ColonelParrot/feedbackplus@master/src/feedbackplus.min.css" /&gt
<script src="https://cdn.jsdelivr.net/gh/ColonelParrot/feedbackplus@master/src/feedbackplus.min.js" defer></script>
<!-- html2canvas import is optionally, but provides better browser
Enter fullscreen mode Exit fullscreen mode

With FeedbackPlus, you can capture screenshots without having to worry about browser support. The library uses the browser's display API to ensure the screenshot is accurate, and fallbacks to html2canvas for better browser support.

Screenshotting

// import FeedbackPlus from 'feedbackplus/src/feedbackplus'
// ^^^ if you're using node ^^^
const feedbackPlus = new FeedbackPlus();
Enter fullscreen mode Exit fullscreen mode
feedbackPlus.capture().then(result => ...)
Enter fullscreen mode Exit fullscreen mode

You can then very quickly just draw the result to a canvas:

const canvas = document.getElementById("canvas")
feedbackPlus.capture().then(({ bitmap, width, height }) => {
  canvas.width = width;
  canvas.height = height;
  canvas.getContext("2d").drawImage(bitmap, 0, 0);
});
Enter fullscreen mode Exit fullscreen mode

Screenshot Example

<canvas id="canvas"></canvas>
<button id="btn">Take screenshot</button>
Enter fullscreen mode Exit fullscreen mode
const canvas = document.getElementById("canvas")
btn.addEventListener('click', () => {
  feedbackPlus.capture().then(({ bitmap, width, height }) => {
    canvas.width = width;
    canvas.height = height;
    canvas.getContext("2d").drawImage(bitmap, 0, 0);
  })
})
Enter fullscreen mode Exit fullscreen mode

Editing Screenshot

Once you have obtained the image bitmap from a screenshot, you can store it in a variable and pass it to showEditDialog to edit it.

feedbackPlus.showEditDialog(bitmap, function (canvas) {
    // user completed edit
    FeedbackPlus.canvasToBitmap(canvas).then(({ bitmap }) => {
      canvas.getContext("2d").drawImage(bitmap, 0, 0);
      feedbackPlus.closeEditDialog();
    });
  }, function () {
    // user cancelled edit
    feedbackPlus.closeEditDialog();
  }
);
Enter fullscreen mode Exit fullscreen mode

It's that easy! Try it out yourself with the demo.

Top comments (0)