0

I need to verify a picture within an img tag is actually being displayed. The images are dynamically created and then sent to the user's browser with javascript. I do wait for the picture loaded event but this isn't enough.

I need to test with certainty if an image is actually being displayed. If I put the image inside a canvas can I use the canvas getImageData(left, top, width, height) method to verify what pixels have been loaded onto the end user's browser?

  • What are you doing that you need absolute certainty that the users machine is behaving a specific way? – castis Jun 07 '17 at 18:18
  • [Possible duplicate](https://stackoverflow.com/questions/1977871/check-if-an-image-is-loaded-no-errors-in-javascript) – snaplemouton Jun 07 '17 at 18:21
  • 2
    It's impossible to prove that an image was visible to the user. Maybe he has an extension that displays cat pictures above all images (if you are talking about legal purposes). – XCS Jun 07 '17 at 18:33
  • 2
    I don't think this is possible. If there is some legal reason for doing this, just have the user confirm they've seen the image - and don't forget about the visually impaired, who can't see it even if it is displayed, and will need some other mechanism offered. – Adrian Jun 07 '17 at 18:34
  • A picture confirmation would be tedious for the users. Is the getImageData the best way to proceed? – UbuntuUser Jun 07 '17 at 23:24
  • Please remove the hold. I have simplified the question. – UbuntuUser Jun 08 '17 at 12:53

1 Answers1

1

Unless I'm mistaken, there is absolutely no way to "prove" with complete certainty what is being rendered on a client's machine, since they could be running any number of scripts client-side that might change or alter what they're actually seeing. You can't "prove" that an unknown user isn't running the Chuck Norris Picture Replacement plugin on Chrome, for example (yes, that's a real thing). They could literally be seeing anything.

And here, I intend to use the word "prove" in the strict sense, not necessarily in the legal sense. To prove something legally in a civil case, you need only a preponderance of the evidence (i.e., anything that would make it more than 50% likely that it's true). So if you can show that it's more likely than not that they saw the picture (as it's unlikely they're using the Chuck Norris Picture Replacement plugin, for example), then you have "proven" that they saw the image as far as you would need to for legal purposes. (I happen to be a lawyer in addition to a web developer, if that generates any additional confidence in the answer I provided).

yoursweater
  • 1,883
  • 3
  • 19
  • 41
  • Thank you for your response. I appreciate you taking the time to answer. Assuming the end user is using a standard web browser, would the pixel checking be a good indication of whether a picture has loaded correctly? – UbuntuUser Jun 08 '17 at 03:51