One day in 1945, a man named Percy Spencer was touring one of the laboratories he managed at Raytheon in Waltham, Massachusetts, a supplier of radar technology to the Allied forces. He was standing by a magnetron, a vacuum tube which generates microwaves, to boost the sensitivity of radar, when he felt a strange sensation. Checking his pocket, he found his candy bar had melted. Surprised and intrigued, he sent for a bag of popcorn, and held it up to the magnetron. The popcorn popped. Within a year, Raytheon made a patent application for a microwave oven.

The history of scientific discovery is peppered with breakthroughs that came about by accident. The most momentous was Alexander Fleming’s discovery of penicillin in 1928, prompted when he noticed how a mould that floated into his Petri dish killed off the surrounding bacteria. Spencer and Fleming didn’t just get lucky. Spencer had the nous and the knowledge to turn his observation into innovation; only an expert on bacteria would have been ready to see the significance of Fleming’s stray spore. As Louis Pasteur wrote, “In the field of observation, chance favours only the prepared mind.”

The word that best describes this subtle blend of chance and agency is “serendipity”. It was coined by Horace Walpole, man of letters and aristocratic dilettante. Writing to a friend in 1754, Walpole explained an unexpected discovery he had just made by reference to a Persian fairy tale, “The Three Princes of Serendip”. The princes, he told his correspondent, were “always making discoveries, by accidents and sagacity, of things which they were not in quest of…now do you understand Serendipity?” These days, we tend to associate serendipity with luck, and we neglect the sagacity. But some conditions are more conducive to accidental discovery than others.

Today’s world wide web has developed to organise, and make sense of, the exponential increase in information made available to everyone by the digital revolution, and it is amazingly good at doing so. If you are searching for something, you can find it online, and quickly. But a side-effect of this awesome efficiency may be a shrinking, rather than an expansion, of our horizons, because we are less likely to come across things we are not in quest of.

When the internet was new, its early enthusiasts hoped it would emulate the greatest serendipity machine ever invented: the city. The modern metropolis, as it arose in the 19th century, was also an attempt to organise an exponential increase, this one in population. Artists and writers saw it as a giant playground of discovery, teeming with surprise encounters. The flâneur was born: one who wanders the streets with purpose, but without a map.

Most city-dwellers aren’t flâneurs, however. In 1952 a French sociologist called Paul-Henry Chombart de Lauwe asked a student to keep a journal of her daily movements. When he mapped her paths onto a map of Paris he saw the emergence of a triangle, with vertices at her apartment, her university and the home of her piano teacher. Her movements, he said, illustrated “the narrowness of the real Paris in which each individual lives”.

To some degree, the hopes of the internet’s pioneers have been fulfilled. You type “squid” into a search engine, you land on the Wikipedia page about squid, and in no time you are reading about Jules Verne and Pliny. But most of us use the web in the manner of that Parisian student. We have our paths, our bookmarks and our feeds, and we stick closely to them. We no longer “surf” the information superhighway, as it has become too vast to cruise without a map. And as it has evolved, it has become better and better at ensuring we need never stray from our virtual triangles.

Google can answer almost anything you ask it, but it can’t tell you what you ought to be asking. Ethan Zuckerman, director of the Centre for Civic Media at Massachusetts Institute of Technology and a long-time evangelist for the internet, points out that it doesn’t match the ability of the printed media to bring you information you didn’t know you wanted to know. He calls the front page of a newspaper a “discovery engine”: the lead story tells you something you’re almost certain to be interested in—the imminent collapse of the global economy, or Lady Gaga’s latest choice of outfit—and elsewhere on the page you learn that revolution has broken out in a country of whose existence you were barely aware. Editors with an eye for such things, what Zuckerman calls “curators”, are being superseded by “friends”—people like you, who probably already share your interests and world view—delivered by Facebook. Twitter is better at leading us to the interests of people beyond our social circle, but our tendency to associate with others who think in similar ways—what sociologists call our “value homophily”—means most of us end up with a feed that feels like an extended dinner party.

One reason why television viewing has held up relatively well, defying predictions of its demise, is that, compared with the internet, it is good at serendipity. Danny Cohen is in charge of BBC1, Britain’s most-viewed channel. He told me that a new programme on a difficult or obscure subject can still inherit a substantial audience from a popular show. This is, in some ways, a mysterious phenomenon. “I could understand it when changing the channel meant getting off the sofa,” says Cohen. “But now?” Despite remote controls and far more channels, we still willingly succumb to the choices of the broadcasting curators.

Cohen worries that even as the volume of media has grown exponentially, “our propensity to explore it is diminishing”. Driven by the needs of advertisers keen to hit ever more tightly delineated targets, today’s internet plies us with “relevant” information and screens out the rest. Two different people will receive subtly different results from Google, adjusted for what Google knows about their interests. Newspaper websites are starting to make stories more prominent to you if your friends have liked them on Facebook. We spend our online lives inside what the writer Eli Pariser calls “the filter bubble”.

To escape it, we can leave our screens and walk outside. But some of our most serendipitous spaces are under threat from the internet. Wander into a bookshop in search of something to read: the book jackets shimmer on the table, the spines flirt with you from the shelves. You can pick them up and allow their pages to caress your hands. You may not find the book you wanted, but you will walk out with three you didn’t. Amazon will have your book too, but its recommendation engine doesn’t even come close to delivering the same stimuli. Similarly, a librarian isn’t as efficient as a search engine, his memory isn’t nearly as capacious, but he may still be better at making suggestions to a reader in search of—well, something.

But there is a reason why Amazon is successful and bookshops are closing: in a world of infinite choice, efficiency is hard to resist. The pleasures of the bookshop or the library are easily outgunned by the knowledge that we can order or download a book instantly, or find the information we’re looking for within seconds. Serendipity, on the other hand, is, as Zuckerman says, “necessarily inefficient”. It is a fragile quality, vulnerable to our desire for convenience and speed. It also requires a kind of planned vagueness. Digital systems don’t do vagueness very well, and our patience with it seems to be fading.

Google’s aim is to organise the world’s information and democratise access to it. But when everyone can get the same information in more or less the same way, it becomes harder to be original; innovation thrives on the serendipitous collision of ideas. Zuckerman told me about a speech on serendipity he recently gave to an audience of investment managers. As he started on his theme he feared he might lose their attention, but he was pleasantly surprised to find that they hung on every word. It soon became clear why. “In finance, everyone reads Bloomberg, so everyone sees the same information.” Zuckerman said. “What they’re looking for are strategies for finding inspiration from outside the information orbit.”

The internet has become so good at meeting our desires that we spend less time discovering new ones. To update the Rolling Stones, you can always get what you want. But you may not get what you need.