A handheld device can identify cancerous tissue in 10 seconds, according to scientists at the University of Texas.
They say it could make surgery to remove a tumour quicker, safer and more precise.
And they hope it would avoid the "heartbreak" of leaving any of the cancer behind.
Tests, published in Science Translational Medicine, suggest the technology is accurate 96% of the time.
The MasSpec Pen takes advantage of the unique metabolism of cancer cells.
Their furious drive to grow and spread means their internal chemistry is very different to that of healthy tissue.
How it works
The pen is touched on to a suspected cancer and releases a tiny droplet of water.
Chemicals inside the living cells move into the droplet, which is then sucked back up the pen for analysis.
The pen is plugged into a mass spectrometer - a piece of kit that can measure the mass of thousands of chemicals every second.
It produces a chemical fingerprint that tells doctors whether they are looking at healthy tissue or cancer.
The challenge for surgeons is finding the border between the cancer and normal tissue.
In some tumours it is obvious, but in others the boundary between healthy and diseased tissue can be blurred.
The pen should help doctors ensure none of the cancer is left behind.
Remove too little tissue, and any remaining cancerous cells will grow into another tumour. But take too much, and you can cause damage, particularly in organs such as the brain.
Livia Eberlin, an assistant professor of chemistry at the University of Texas, Austin, told the BBC: "What's exciting about this technology is how clearly it meets a clinical need.
"The tool is elegant and simple and can be in the hands of surgeons in a short time."
The technology has been tested on 253 samples as part of the study. The plan is to continue testing to refine the device before trialling it during operations next year.
The pen currently analyses a patch of tissue 1.5mm (0.06in) across, but the researchers have already developed pens that are even more refined and should be able to look at a finer patch of tissue just 0.6mm across.
While the pen itself is cheap, the mass spectrometer is expensive and bulky.
Dr Eberlin said: "The roadblock is the mass spectrometer, for sure.
"We're visioning a mass spectrometer that's a little smaller, cheaper and tailored for this application that can be wheeled in and out of rooms."
Dr James Suliburk, one of the researchers and the head of endocrine surgery at Baylor College of Medicine, said: "Any time we can offer the patient a more precise surgery, a quicker surgery or a safer surgery, that's something we want to do.
"This technology does all three."
The MasSpec Pen is the latest attempt to improve the accuracy of surgery.
A team at Imperial College London have developed a knife that "smells" the tissue it cuts to determine whether it is removing cancer.
And a team at Harvard are using lasers to analyse how much of a brain cancer to remove.
Dr Aine McCarthy, from Cancer Research UK, said: "Exciting research like this has the potential to speed up how quickly doctors can determine if a tumour is cancerous or not and learn about its characteristics.
"Gathering this kind of information quickly during surgery could help doctors match the best treatment options for patients sooner."