That’s a good approach and really helps develop the ear. It was, after all, how the old fogies among us like me learned - playing along to the radio or to records.
There’s absolutely a degree of innate skill involved there but a lot can be achieved by practice ad studying the right things - over time, of course! And being thrown into the deep end at something like a jam really sharpens up the skills and focuses the mind!! 🤣 When I was in my 20s I would play in the worship band at church, led by a friend of mine on acoustic guitar. He was quite disorganised and rarely knew what songs we were going to play until the Sunday morning. Often he didn’t know what songs he was going to do next during the service and wouldn’t necessarily start them up with the correct chords or in the right key. So I had to learn to busk/jam along early on and me and the keys player spent many services squinting at his left hand to work out the key and chords!
Also, learning to play songs from chord sheets was helpful in terms of working out how to link notes and chords together on the fly.
In terms of learning and developing skills, the things that were really the lightbulb moments for me were…
Learning the major and minor scales and, in particular the shapes related to them on the fretboard,
Learning and getting an innate feel for what different intervals sounded like - third, fourth, fifth, major and minor sevenths - that just takes lots of practice and repetition, but the BIG one was…
Understanding the harmonised major and minor scales and how they related to common song chord structures. That is (not sure how much folk have looked at this) understanding how the standard chords in a particular key are made up from notes of that scale and that the pattern of major / minor chords is the same across different keys. Knowing that, for most mainstream rock/pop, if you’re in the key of G, the most likely chords to come up are G major, A minor, B minor, C major and D major really - or if you’re in A then it’s A major, B minor, C# minor, D major and E major - really helps navigate the way through a song you’re not familiar with. And of course, that’s where the understanding of intervals helps identify the next chord.
Starting to understand the commonly used chord patterns was a huge thing when combined with the above. Al the last country jam I ended up playing a few songs I’d not heard before and it was really helpful when the guitarist said, “It’s a simple 1 -4-2-5 in G…” (i.e. G major, C major, A minor, D major) and I immediately had a mental roadmap for the notes I should be aiming for to begin with.