3

I am trying to detect when an HBO Go movie has completed using javascript. Unfortunately, HBO Go uses Flash, and I have no Flash experience.

I noticed that when the movie ends, the Chrome javascript console shows this:

00:02:30:0596 TimeEvent.COMPLETE
    (anonymous function) @ VM12786:1

I followed VM12786:1 and found this:

try { __flash__toXML(console.error("00:02:30:0596 TimeEvent.COMPLETE")) ; } catch (e) { "<exception>" + e + "</exception>"; }

I'm not quite sure what either of these mean. Can someone briefly explain it? I have extensively googled, but haven't found anything that I understand.

And, is there any way that I can detect with javascript or jQuery that this has been triggered?

JSW189
  • 6,267
  • 11
  • 44
  • 72

2 Answers2

2

Here's a briefing on those JS bits:

try {
    __flash__toXML(console.error("00:02:30:0596 TimeEvent.COMPLETE"));
} catch (e) {
    "<exception>" + e + "</exception>";
}

The __flash__toXML function is a mechanism to allow the Flash program to communicate with the webpage via JavaScript (brief explanation here, unrelated article). It seems like that snippet is part of a larger section that handles the video ending event.

The weird stringy thing seems like a useless piece of code that is just there as a placeholder, but I would need to look at the context to understand it better. As it is, it does nothing.

Here's my answer to your question:

Unfortunately, there's no event you can capture for console actions directly. You would need to replace the functions with your own that trigger a custom event, and then handle that event. This article explains the process excellently. You would need to modify the internal intercept function to trigger an event on the main window, which you can handle in the traditional ways:

$(window).trigger("myapp.console.log");

Note: This may not work for content scripts, but that's advanced and depends on implementation. If you are using something injected into the browser, replacing the function will only affect the content script's sandbox.

cyberbit
  • 1,345
  • 15
  • 22
  • I agree. That `Try/Catch` block almost looks like "just testing" code, doesn't it? Anyway unless the Flash app is programmed to send out a javascript event when playback completes then its impossible (a plugin is not in same domain/context as the other html content). He really needs to check the html source for the HBO video page, maybe there are clues for some events? Otherwise not gunna happen. HBO & Netflix are not trying to be like the Youtube API – VC.One Jun 29 '15 at 07:29
  • Yea, it doesn't seem like production code at all. It seems like Flash may be sending out an event that's triggering it, though, which _may_ be something that's capturable using JS. – cyberbit Jun 29 '15 at 14:47
  • As I understand it from the question, the console does show the error message, so even if the code looks a bit strange, it still creates a capturable event in javascript, no? That's why I gave the answer about hijacking the console.error function. Would that not work? – m69's been on strike for years Jun 29 '15 at 16:07
  • The console does show the message, so yes, there is something capturable. Your idea is totally correct, I just pointed the OP to an article with a better description and solution than either of us could offer. I updated my answer with a small bit of clarification on what I meant by "no event." – cyberbit Jun 29 '15 at 16:14
1

I learned on StackOverflow that you can hijack the console functions, as in the example, where I've added an alert to the console.error function.

var conerr = console.error;

console.error = function()
{
    alert("console error: " + arguments[0]); /* do stuff here */
    return conerr.apply(console, arguments);
}

setTimeout(function() {console.error("00:02:30:0596 TimeEvent.COMPLETE");}, 1000);