Earliest mention I've seen is the real-life product, "Shark Chaser", used by the United States Navy from 1943-1973.
Initial work, which was based on historical research and studies at the time, focused on using the odor of another dead shark. Efforts were made to isolate the active components in dead shark bodies that repelled other sharks. Eventually, it was determined that certain copper compounds like copper acetate, in combination with other ingredients, could mimic a dead shark and drive live sharks away from human beings in the water. Building on this work, Stewart Springer and others patented a "shark repellent" consisting of a combination of copper acetate and a dark-colored dye to obscure the user. This shark repellent, known as "Shark Chaser," was long supplied to sailors and aviators of the United States Navy, initially packaged in cake form using a water-soluble wax binder and rigged to life vests. The Navy employed Shark Chaser extensively between 1943 and 1973. It is believed that the composition does repel sharks in some situations, but not in all, with about a 70% effectiveness rating.
However, that was in cake form, not a canned spray.
For earliest example of a spray in fiction, it looks to be from a 1958 Batman comic, Batman #117, in the story "Manhunt in Outer Space":