Many years ago I remember taking charter flights which made a scheduled stop in BGR, we cleared CBP there, so when arriving in JFK the flight arrived as a "domestic".
Probably wouldn't work with the timeframe of a tech/fuel stop on a scheduled flight unless set up for it (i.e. BA 001 at SNN on a much smaller bird). Clearing CBP requires all cargo to be unloaded and inspected, checked luggage given back to pax to carry through FIS, then everything rechecked and reloaded. All personnel on board (including crew) need to deplane to clear FIS, and all foreign-origin catering must be discarded, then replaced with any onward catering desired by the airline. The empty aircraft cabin would also need to be CBP-inspected before it could be reloaded, recrewed, and reboarded.
IMHO, no way to do that in the (relatively minimal) time required to refuel and preflight the bird.