Wow, thanks R0J0hound, that's super helpful.
Sprite loadURL code
I just looked up the Sprite's loadURL code.
I see what look like 4 parts to the code.
1. Declare some variables, including the image "img". [3 lines]
2. Assign an onload() function. [a bunch of lines]
3. An if-statement that checks stuff about the "url_". [2 lines]
4. Finally "img.src = url_;". [1 line]
So does that final assignment in part 4 "img.src = url_;" trigger the onload() function assigned in part 2? Or rather, does the completion of loading that newly assigned URL trigger it?
Because otherwise I'm not sure where the loading of the image is happening.
If that's the case, I may understand what's going on in your code. I think the assignment of that onload() function just threw me a bit, because it looked like nothing explicitly called it. So I'm assuming that again the assignment to img.src sets some behind-the-scenes stuff in motion that ultimately triggers the onload() function.
Possibly realized my in-event color picking troubles
As an added bonus, when looking through the Sprite's loadURL code, I may have figured out why my previous in-event attempts to pick colors acted so finicky. I think I was waiting till the screenshot was taken, via the triggered event, but I wasn't waiting until after I was done loading it into a sprite, via the sprite's triggered event.
I've been trying to pick the post-webgl colors out of the 3rd party Canvas plugin by saving a screenshot with the System action, loading the screenshot into a Sprite, and then pasting that screenshot Sprite into a Canvas plugin, so I can pick it's colors. I keep forgetting that every image loading step is going to be asynchronous, not just the screenshot.
Some questions about your code example
Will the "canvas.getContext('2d');" in your first code example work if webgl is enabled?
Or does that not matter because, once inside the onload() function, we're dealing with our own custom canvas for the screencap, rather than C2's game canvas?
Thoughts on readpixels
The "working only on frame one" thing might be because of how buffer clearing works when using webgl with preserveDrawingBuffer set to false, which I assume it is for C2 for performance reasons. Not sure though.
At the second link you posted one of the comments seems to indicate that it might be possible to get data from the buffer after it's drawn but before it's handed to the compositor and cleared. Granted that would require inserting code into C2's runtime I gather, which is probably not the direction I should be going. Of course I could be totally wrong about all of the above, I'm just trying to follow along.
So I set up the plugin and implemented the example code, but I'm always getting [ 0 , 0 , 0 , 255 ] as the pixel values regardless of the coordinates I use. I'm using an alert() to print the pixel directly out of the onload() function, right after the call to ctx.getImageData().
Still working on figuring out what's going on, but I'm open to any suggestions.
Do I maybe need to wait for some aspect of the C2 canvas to load before passing it to "img.src"?