Add object and shadow over a background using the compositor I am doing an animation with a camera to add 3D elements to it (don't really know what it is called)

As you can see in the picture above, i am trying to use nodes to assemble my shadow, object and background for the final render, but for my shadow, some of the plane is still visible... I tried using a "Dilate/Erate" node to mask the plane but it ends up also hiding the shadow.

Do you guys have any idea on how I can fix this? Thank you
In my opinion you are overcomplicating things.

Since you are using the new shadow catcher feature available in 2.78.5 you don't need to do much.

Set the plane that will receive the shadow, and set it to be a shadow catcher in Cycles Settings> Ray Visibility.

 

The rendered image will have the shadow and the rest of the plane will be transparent:



Then just overlay the rendered image onto your background using Alpha Over: