For controlling a browser you could look into the extension MozRepl https://github.com/bard/mozrepl/wiki. It gives you a read-eval-print-loop for evaluating javascript code. It is used for example by the WWW::Mechanize::Firefox module. I have not used it myself, but the documentation sounds as it should be possible to control a browser canvas externally.