Hi Ai,
Thanks for posting your question.
Yes, it's possible using JS. The manual says that screen_save isn't available for HTML5 targets because Game Maker uses the browser's local storage for the file system, and it's too small for large images (1-5mb).
Here's something I hacked together that works on Chrome/Edge. If you put this in "prepend output.js" in the HTML5 settings it creates a button you can press underneath the game window that will take the screenshot and download it.
JavaScript:
// Create download element
var screenshotDownload = document.createElement("a");
screenshotDownload.download = "screenshot.jpeg"; // name of file
// Create the screenshot download button
var button = document.createElement("button");
button.innerText = "Take Screen Shot";
// Click callback
button.addEventListener("click", function() {
var canvas = document.getElementById("canvas");
// Retrieve the data
var img = canvas.toDataURL("image/jpeg");
screenshotDownload.href = img;
screenshotDownload.click();
screenshotDownload.href = "";
});
document.body.appendChild(button);
You'll also need to turn off WebGL in the HTML5 settings because Game Maker doesn't set the gl context's preserveDrawingBuffer flag to true on creation. Every time you request the image data with Canvas.toDataURL it will only return a blank image from the data getting cleared by the time the call is made. I think there's another way to do this by retrieving pixel data within webgl, but using toDataURL is probably the most straightforward.
Edit: It looks like there's a way to take a screenshot with preserveDrawingBuffer set to false in this thread
https://stackoverflow.com/questions/30628064/how-to-toggle-preservedrawingbuffer-in-three-js
And I'm sure YellowAfterlife has solved in the extension
@rIKmAN posted.
Hope this helps!