The etymology of the phrase, clutching at straws, is thought to have originated in the work of Thomas More called, Dialogue of Comfort Against Tribulation (1534).
See More’s Utopia on this blog.
The idiom clutching at straws is therefore meant to refer to a drowning person grasping for anything, even a straw, to save their life (straw, like wooden logs, floats on water but, whereas a log wouldn’t sink if a person were to hold on to it for dear life*, straw probably would sink). Nowadays, the phrase has come to mean something like this:
— to act or make a decision, usually in desperation, without there being much hope of success.

p.s.
* British English 🇬🇧 is full of references to the sea because, being an island, have a deep relationship with the seas and, if you were at sea and had fallen overboard (off of a boat or a ship) you’d hope not to end up in, Davy Jones’ Locker.
Davy Jones’ Locker is an idiom for the bottom of the sea: the state of death among drowned sailors and shipwrecks. The phrase then is used as a euphemism for drowning (at sea) 🏴☠️.


