I had been struggling to find a decent working example for javascript selenium webdriver with chromedriver to do a fullpage screenshot, so finally i manage to make it working and then attach it with cucumber js reporting

See example below.
https://github.com/seanlon/cucumber-js-selenium-fullpage-screenshot

snippet
https://github.com/seanlon/cucumber-js-selenium-fullpage-screenshot/blob/8e9ef4334276eff4e38f7c57c72d0bd4439c017f/features/steps/common-steps.js#L38

How?
1. Use selenium webdriver executeScript to inject script js first a plugin html2canvas in the html page you are testing
2. Then initiate the html2canvas callback to add a canvas into the html page document.body
3. Once done, access the canvas and use toDataUrl and create image element, you should be able to get the base64 image.

4. After that just accceses the image html element and write the base64 data into your file.

5. Lastly , don’t forget to remove the created/generated canvas and image element.

Full working code example here
https://github.com/seanlon/cucumber-js-selenium-fullpage-screenshot/blob/8e9ef4334276eff4e38f7c57c72d0bd4439c017f/features/steps/common-steps.js#L38