The MasSpec Pen could replace the frozen section analysis method of finding cancerous tissue - which is slow and unreliable.
Scientists have invented a device the size of the pen which can detect cancer in a matter of seconds, aiding surgeons to remove "every last trace" of the disease.
The device is capable of identifying cancerous cells 150 times faster than conventional technologies and was 96% accurate in tests.
Researchers from the University of Texas say that the MasSpec Pen can help surgeons identify which tissue should be removed and which should be preserved, to help patients' recover.
Dr Livia Schiavinato Eberlin, who designed the study, said: "If you talk to cancer patients after surgery, one of the first things many will say is 'I hope the surgeon got all the cancer out'.
"It's just heartbreaking when that's not the case. But our technology could vastly improve the odds that surgeons really do remove every last trace of cancer during surgery."The MasSpec Pen works by releasing a tiny droplet of water onto the target tissue, absorbing the chemicals inside of the cells.
This droplet is then analysed by an instrument called a mass spectrometer, which can analyse thousands of molecules, and quickly deliver the results to doctors on a computer screen.
Currently, distinguishing between cancerous and normal tissues involves a slow and unreliable process called frozen section analysis.
It can be risky because if a surgeon is unable to remove enough of the cancerous tissue it can allow tumours to regrow, but removing too much healthy tissue can also have detrimental effects.
These can be painful and could involve nerve damage in breast cancer patients, while thyroid patients could lose their abiltiy to speak.
James Suliburk, 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. It allows us to be much more precise in what tissue we remove and what we leave behind."
The study has been published in the Science Translational Medicine journal, and the team hopes to start testing the device during surgeries next year.