If you're looking for something broader, like if the entity is just on the player's screen, that's significantly more difficult, as you would have to do math to get the player's rotation, and then an "arc" in that direction, and then test if the entity is within that arc. This would require a lot of circle math, which I am not personally fond of.
This plugin has a block for raytracing to test if the player is looking at the entity - https://mcreator.net/plugin/99695/typecast
If you're looking for something broader, like if the entity is just on the player's screen, that's significantly more difficult, as you would have to do math to get the player's rotation, and then an "arc" in that direction, and then test if the entity is within that arc. This would require a lot of circle math, which I am not personally fond of.