I use the screenshot command, it's not Javascript but it works for me. Documented here and here
Then, press Ctrl + Shift P (PC) or Command + Shift P (Mac) or click the three-dot menu for "Customize And Control DevTools" and select
Run Command. Type "screenshot" to see the screenshot options, which are:
- Capture area screenshot
 - Capture full size screenshot
 - Capture node screenshot
 - Capture screenshot