My car has 9007 bulbs. One side has a bulb that works and then not. I changed bulb but old one tested fine. Then I saw the fuses were blown. Fixed fuses. No light. I tapped new light bulb and it came on. 2 days later no light. Took it out and it checks ok. The wire harness has 3 wires and they go into this device. Then the harness goes into engine bay, what is this device? Where is the ground wire? There is no ground lug in area.
Looks like a lot of corrosion on those metal contacts. It’s probably in the part that connects there, too. I would use electrical contacts spray cleaner and a toothbrush on all affected parts. Maybe even a brass brush.
The ground may be the screws or whatever holds that part against the metalwork.
Oh, one time the headlight bulb was about 1/2 brightness. So, on, off, or in between. I could remove device and see what backside looks like. And clean any corrosion like you say. Or get a better pic and look it up
Is that a QR code on the part? If so, try scanning it.
That is an impact sensor for the airbag control module. You don’t need to clean it with a toothbrush, hit it with a hammer and see if the airbags deploy.
For the headlight, look inside the connector for heat damage, the connection is loose.
I had to replace the headlight sockets before. I bought the last one off the shelf at Pep Boys. The socket comes with a few inches of wire. Cut the old wires, strip both sides and solder them together. I put heat shrink tubing on the wires before soldering them, then used the soldering iron to shrink the tubing.
Why does bulb wire go into impact sensor?