Warning: possibly involves a set of programming bad practices to bypass security features.
We're developing a bundle of scripts that extract public information from some website. I use ViolentMonkey to inject scripts in the website, which uses Google's reCAPTCHA (see example).
To bypass it, I installed Buster: Captcha Solver, a very neat extension which places an icon on reCAPTCHA frames which, upon clicked, switches to audio solving mode and tries to transcribe the audio. It will fail every other attempt, but it's quite helpful.
The thing is: Buster detects reCAPTCHA is loaded - there doesn't seem to be enough a reason for it to require a user click. I wouldn't say it defeats the purpose, but I would rather have it run automatically. I even injected a pre-click which pops open the reCAPTCHA modal (and yes, it works), but I can't force-click Buster's icon because it is enclosed in a closed shadow DOM.
Buster basically uses shadowRoot.appendChild()
, so I tried setting @run-at document-start
and tampering with HTMLElement.prototype.attachShadow
:
HTMLElement.prototype.attachShadow = function(args) {
return this;
};
This would theoretically make shadowRoot.appendChild()
append the child directly to the node itself, but Buster is still able to attach the shadow DOM regardless. I believe overwriting HTMLElement.prototype
will only work for the current global scope, and Buster is sandboxed in its own extension's environment. Had it worked, something like this would most likely be possible:
// and yeah, that's really all I'm trying to achieve
document.querySelector('.button-holder.help-button-holder')
.shadowRoot
.getElementById('solver-button')
.click();
I thought of compiling a modified version of Buster's source code in which I simply use .attachShadow({mode: 'open'})
so my scripts can finally access its button, but that'd be too much of a hassle right now. I also can but don't want to use tools outside of Chrome (like AutoHotkey) for this.
TL;DR
How can I programmatically click an element inside a closed shadow DOM with ViolentMonkey/TamperMonkey?