I'm trying to monkey patch this node module in electron application. I want to change the capture method input arguments.
My code so far looks like this:
if (process.platform == "darwin") {
let refSCapt = screenshot.capture;
console.log("Outside");
screenshot.capture = function(output: string, callback: any) {
console.log("Inside");
// Override output path of a temp .png file
let tempOutput = output.split("/")[-1];
refSCapt(this.screenshotsPath + tempOutput, callback);
};
}
The problem is that the patch is not reflecting and the original method is called as if nothing would've change. The Outside get's logged but the Inside is never called.
So how can I monkey patch this module method?
So how can I monkey patch this module method?
What you have would work fine ... but only if your code runs before it is used elsewhere. For reliable patching I recommend https://github.com/ds300/patch-package which patches modules on install.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With