While it may seem impossible, there are actually ways to modify Angular services, which are normally singletons. Once a service is instantiated, the instance is typically stored in a private variable with no direct way to override it.
However, if the factory was created as an object with multiple methods, these methods can be monkey-patched for modification:
var factory = angular.element(document.querySelector('.ng-scope'))
.injector()
.get('factoryName');
var factoryMethod = factory.methodName;
factory.methodName = function () {
console.log(arguments);
return factoryMethod.apply(factory, arguments);
};
In alternative scenarios, it's possible to intercept the app during its bootstrapping process using tools like Greasemonkey or Tampermonkey. This allows for the replacement of components from the original module with a new module, or adding a new config
block to the original module where a defined factory can be modified using $provide.decorator or redefined with $provide.factory.