These are rain gutters.
They are designed to catch rain that runs off the upper surface of the aircraft fuselage and channel it away from the open aircraft door so that the water does not enter the cabin.
This is a close up of the rain gutter over the main cabin door of a Beechcraft King Air B200, showing the channel that would catch and redirect water flow to the side of the door opening:
Source: own work
A jet-bridge may partially deflect rainwater in some cases, but the gutter helps mitigate water exposure for the aircraft interior and passengers. Even gutters cannot completely eliminate such exposure since their size is necessarily limited by aerodynamic constraints. Many operations do not have the luxury of jet-bridges, making the rain gutter especially helpful in reducing the amount of water that might otherwise enter the cabin and pose a hazard to the aircraft or onboard systems.
"Rain Gutters" is the technical name, at least for Boeing aircraft, such as the B777 depicted in the photos in the question.
Here is a Boeing reference to such gutters on the 787:
Rain gutter: When customers found that water was not being properly deflected over a passenger entry door, they requested a change. Boeing relocated the gutter to function more efficiently. The solution means happy customers, who had fewer water and maintenance issues, and happier and drier passengers. This was a significant enough change to process to require certification work with the FAA.
It's for the passengers on a rainy day. If this strip would not be diverting the rainwater flowing from the upper fuselage, a curtain of water would soak the passengers upon entering or leaving the aircraft, and the cabin floor.
These rain gutters are for deflecting the rain from entering the cabin. Even with Jet-bridges, the door itself might be covered, but since the whole cylindrical fuselage is not. The rain that falls in the uncovered area at the top of the fuselage would roll down, then going under the jet bridge's cover. This is to redirect that water that would have gone into the doorway off to the side.
It's used so when they are attaching the air bridge, it helps the top of it to align.