---
title: "How to take a map screenshot with Ybug | JavaScript maps SDK"
description: "Take map screenshot with Ybug integration using helper."
---

> For AI agents: a documentation index is available at [/llms.txt](https://docs.maptiler.com/llms.txt). Markdown versions of all pages are available by appending .md to any URL.

# How to take a map screenshot with Ybug

This tutorial addresses the common issue of blank images (missing maps) appearing in screenshots instead of a beautiful map displays when using Ybug reporting and feedback tool.

1.  Create a simple web page where we will add a map.
    
    ```html
    <!DOCTYPE html>
     <html lang="en">
     <head>
         <meta charset="UTF-8">
         <meta name="viewport" content="width=device-width, initial-scale=1.0">
         <title>Maptiler screenshot</title>
         <script src="https://cdn.maptiler.com/maptiler-sdk-js/v4.2.0/maptiler-sdk.umd.min.js"></script>
         <link href="https://cdn.maptiler.com/maptiler-sdk-js/v4.2.0/maptiler-sdk.css" rel="stylesheet" />
         <style>
             body {
               margin: 60px 40px;
               font-family: Arial, sans-serif;
             }
             #map-container {
                 width: calc(100% - 80px);
                 height: calc(100vh - 120px);
                 position: relative;
                 margin: auto;
                 box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
             }
             .maptiler-logo {
               position: absolute;
               top: 10px;
               left: 80px;
             }
         </style>
     </head>
     <body>
         <div class="maptiler-logo">
           <a href="https://www.maptiler.com/" target="_blank">
             <img src="https://www.maptiler.com/styles/style/logo/maptiler-logo-adaptive.svg" alt="MapTiler Logo">
           </a>
         </div>
         <div id="map-container"></div>
         <script>
             maptilersdk.config.apiKey = "YOUR_MAPTILER_API_KEY_HERE";
    
             const map = new maptilersdk.Map({
               container: document.getElementById("map-container"),
               style: maptilersdk.MapStyle.STREETS,
               geolocate: true,
             });
         </script>
     </body>
     </html>
    ```
    
2.  Insert your valid [MapTiler API key](https://cloud.maptiler.com/account/keys/) in place of `YOUR_MAPTILER_API_KEY_HERE`.
    
3.  Insert the Ybug snippet. Copy this code into your webpage, right before the closing `</body>` tag or view the [Ybug installation guide](https://ybug.io/docs/installation)
    
    ```html
    <script type='text/javascript'>
     (function() {
         window.ybug_settings = {"id":"YOUR-YBUG-PROJECT-ID"};
         var ybug = document.createElement('script'); ybug.type = 'text/javascript'; ybug.async = true;
         ybug.src = 'https://widget.ybug.io/button/'+window.ybug_settings.id+'.js';
         var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ybug, s);
     })();
     </script>
    ```
    
4.  Replace `YOUR-YBUG-PROJECT-ID` with your designated Ybug project id.
    
5.  Reload the page. Here is what the basic web page looks like:
    
    ![Basic web page with a map and feedback button](./webpage-map-feedback-button.webp)
    
6.  Get user feedback. Click the Feedback button to Report an issue. Thanks to the Feedback widget with screen capture, you can collect not only the feedback of your users but also take screenshots or screen recordings from their browsers.
    
7.  Utilize the integrated feedback tools to annotate the map by drawing relevant markings and complete the detailed issue submission form with pertinent information.
    
    ![Ybug feedback report](./feedback-report-issue-form.webp)
    
8.  Click the Submit button to send your feedback.
    
9.  Review the user feedback. Access the Ybug dashboard interface and select the specific issue report created during the previous step.
    
10.  Open the attached screenshot image. Sadly, you’ll notice the screenshot appears in the Ybug dashboard without the map image (no map image). This is how the screenshot looks in the Ybug dashboard:
     
     ![Ybug dashboard feedback report](./feedback-blank-map-image.png)
     
11.  Make the rendering buffer available. Use the Ybug’s `beforescreenshot` event which allows you to perform any necessary preparations or modifications to the page before the screenshot is taken. Read more about other [Ybug events](https://ybug.io/docs/installation#js-events).
     
     ```js
     const map = new maptilersdk.Map({
        container: document.getElementById("map-container"),
        style: maptilersdk.MapStyle.STREETS,
        geolocate: true
      });
     
      map.on('ready', () => {
        Ybug.on('beforescreenshot', () => {
          // Do some sync work here...
     
          // If you need to perform some async actions, you can return a Promise
          return new Promise(async(resolve) => {
            // Do some async work...
            resolve();
          });
      });
     ```
     
12.  Get the map screenshot using the [MapTiler SDK screenshot helper](https://docs.maptiler.com/sdk-js/api/helpers/#screenshot).
     
     ```js
     map.on('ready', () => {
        Ybug.on('beforescreenshot', () => {
          // Do some sync work here...
          const mapCanvas = map.getCanvas();
     
          // If you need to perform some async actions, you can return a Promise
          return new Promise(async(resolve) => {
            // Do some async work...
            const mapBlob = await maptilersdk.helpers.takeScreenshot(map);
            //Convert Blob to dataURL
            const a = new FileReader();
            a.onload = function(e) {
              mapCanvas.toDataURL = (type, quality) => {
                 // Return the screenshot directly (e.g., Base64 string)
                 return e.target.result;
              };
              resolve();
            }
            a.readAsDataURL(mapBlob);
          });
      });
     ```
     
13.  Create an issue report using the feedback button.
     
14.  Access the Ybug dashboard and locate your newly created issue report.
     
15.  View the attached screenshot image to confirm the successful capture of the map image. Now you have the map image in the report.
     
     ![Ybug dashboard feedback report with a map image](./feedback-map-image.webp)
     

### Complete source code

```html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Maptiler screenshot</title>
  <script src="https://cdn.maptiler.com/maptiler-sdk-js/v4.2.0/maptiler-sdk.umd.min.js"></script>
  <link href="https://cdn.maptiler.com/maptiler-sdk-js/v4.2.0/maptiler-sdk.css" rel="stylesheet" />
  <style>
    body {
      margin: 60px 40px;
      font-family: Arial, sans-serif;
    }
    #map-container {
      width: calc(100% - 80px);
      height: calc(100vh - 120px);
      position: relative;
      margin: auto;
      box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    }
    .maptiler-logo {
      position: absolute;
      top: 10px;
      left: 80px;
    }
  </style>
</head>
<body>
  <div class="maptiler-logo">
    <a href="https://www.maptiler.com/" target="_blank">
      <img src="https://www.maptiler.com/styles/style/logo/maptiler-logo-adaptive.svg" alt="MapTiler Logo">
    </a>
  </div>
  <div id="map-container"></div>
  <script>
    maptilersdk.config.apiKey = "YOUR_MAPTILER_API_KEY_HERE";

    const map = new maptilersdk.Map({
      container: document.getElementById("map-container"),
      style: maptilersdk.MapStyle.STREETS,
      geolocate: true,
    });

    map.on('ready', () => {
      Ybug.on('beforescreenshot', () => {
        // Do some sync work here...
        const mapCanvas = map.getCanvas();

        // If you need to perform some async actions, you can return a Promise
        return new Promise(async(resolve) => {
          // Do some async work...
          const mapBlob = await maptilersdk.helpers.takeScreenshot(map);
          //Convert Blob to dataURL
          const a = new FileReader();
          a.onload = function(e) {
            mapCanvas.toDataURL = (type, quality) => {
               // Return the screenshot directly (e.g., Base64 string)
               return e.target.result;
            };
            resolve();
          }
          a.readAsDataURL(mapBlob);
        });
      });
    });
  </script>
  <script type='text/javascript'>
  (function() {
      window.ybug_settings = {"id":"YOUR-YBUG-PROJECT-ID"};
      const ybug = document.createElement('script'); ybug.type = 'text/javascript'; ybug.async = true;
      ybug.src = 'https://widget.ybug.io/button/'+window.ybug_settings.id+'.js';
      const s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ybug, s);
  })();
  </script>
</body>
</html>
```

## Learn more

If you want to know the reasons why these feedback tools return a blank image and why this implementation approach was necessary, you can find full technical details in [How to fix a missing map from feedback button](https://docs.maptiler.com/sdk-js/examples/helper-screenshot-feedback/).

## Related examples

### [Download a map screenshot (screenshot helper)](https://docs.maptiler.com/sdk-js/examples/helper-screenshot-download/)

Examples

Download map screenshot as PNG file using helper.

### [Take screenshot (screenshot helper)](https://docs.maptiler.com/sdk-js/examples/helper-screenshot/)

Examples

Capture map view as PNG blob using helper.

### [Missing map from feedback button](https://docs.maptiler.com/sdk-js/examples/helper-screenshot-feedback/)

Tutorials

Fix missing map in feedback using screenshot helper.

### [Screenshot with Usersnap](https://docs.maptiler.com/sdk-js/examples/helper-screenshot-usersnap/)

Tutorials

Take map screenshot with Usersnap integration using helper.
