I am looking for a method that can automatically click on the interactive choices in some Netflix movies.
I've tried a lot of things, but it seems that only the focus event works:
document.getElementsByClassName("BranchingInteractiveScene--choice-selection")[0]
.dispatchEvent(new Event('focus'));
Using .click(), .dispatchEvent(new Event('mousedown')) and many similar methods on this element does not work for some reason.
Looking at things in the inspector from Firefox, you can see the click method is missing. But a normal click with the mouse on that element works just fine.
Anyone got an idea what other methods I could try out, to make this work?
UPDATE 1: Just found out about this debug function in firefox. Hopefully it tells me how the click event needs to look like.
UPDATE 2: With this debug tool I now managed to trigger click events almost identical to the ones a normal mouse click creates. The only two non-identical properties left are isTrusted (is false instead of true) and mozInputSource (is 0 instead of 1). Here is the code I got so far:
const wrapperClassName = "ResizingAspect--wrapper";
const containerClassName = "ResizingAspect--container";
const choicesClassName = "BranchingInteractiveScene--choice-selection";
function clickChoice(choiceNr) {
document.activeElement.blur();
const wrapper = document.getElementsByClassName(wrapperClassName)[0];
const container = document.getElementsByClassName(containerClassName)[0];
const button = document.getElementsByClassName(choicesClassName)[choiceNr];
if (!button) throw new Error("Unable to find element");
const bounding = button.getBoundingClientRect();
const x = bounding.left + bounding.width / 2;
const y = bounding.top + bounding.height / 2;
var event = new MouseEvent("click", {
view: window,
bubbles: true,
cancelable: true,
clientX: x,
clientY: y,
composed: true,
detail: 1,
screenX: x + (wrapper.clientWidth - container.clientWidth) / 2,
screenY: y + (wrapper.clientHeight - container.clientHeight) / 2,
});
// FIXME isTrusted != true;
// FIXME mozInputSource != 1;
button.firstChild.dispatchEvent(event);
console.log("clicked (" + x + ", " + y + ")");
}
It still does not select the choices automatically though... My guess would be that the problem lies in the isTrusted = false part.
UPDATE 3:
It is not the most beautiful workaround, but as I haven't found any real solution so far what follows is better than giving up. That said, I have now written a java overlay application that uses the java.awt.Robot class which works as an autoclicker. That java application is then controlled by http requests from the Firefox add-on sent over localhost.

