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.
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.