Color Replacement Shader Antialiasing

Is there a way to do a color replacement shader without antialising breaking it? I have tried with 3 different versions:

Multipipeline: Phaser Sandbox
PostFX: Phaser Sandbox
PreFX: Phaser Sandbox

They all seem to have the same results. If you turn off antialising then the color replacement works. With antialising it does not because the shader appears to run after the antialising pass happens and the colors aren’t what they are expecting anymore. If you turn up the epsilon param it sort of works but you can still see a line at the edge where it doesn’t replace, and then it also starts replacing other colors it shouldn’t so it is a bad solution.

Right now I’m just sending all of the image data to a web worker and in there I iterate through each pixel and replace it as needed. This is also a crappy solution since it is CPU intensive and slow to run for dozens of sprite sheets since is a RTS with lots of units to convert. It seems like there should be a shader way to do this, but really I need something to run BEFORE antialising and I have no idea how to do that.