There are two possible scenarios:
- US-EWR-Canada: no immigration/customs in the US; clear Canadian immigration/customs on arrival Canada.
- Third country-EWR-Canada: clear US immigration/customs on arrival at EWR; clear Canadian immigration/customs on arrival in Canada.
Either way, you always clear Canadian immigration/customs upon arrival in Canada. Note that when you check in for your flight, the airline will likely want to see your passport.
As cestmoi123 said, if you're flying
from Canada
to EWR, you will usually preclear US customs/immigration in Canada before boarding, but I don't think any foreign governments have customs preclearance at US airports. Here's a list of the airports in Canada (and a few other countries) that have US customs/immigration preclearance:
https://www.cbp.gov/border-security/...s/preclearance