Sharpies can be good on plastic (including foamed plastic like EVA craft foam) but they're not always the best choice.
Here I've tested (top row, blue) a Schwan Stabilo OHPen 841 universal permanent superfine and on the bottom (pink) a fine Sharpie.
On both rows, from the left the mark was
- made and immediately smudged
- made, left about 10 seconds then smudged (rubbed hard in the case of the OHPen)
- gone over 3 times, then smudged (again, rubbed vigorously for the blue)
- made and left
- gone over 3 times and left
A few minutes later, after taking the photo and typing this answer, the Sharpie still smudges.
Permanent overhead projector pens aren't available in as many colours as sharpies, but are very useful for marking on many plastic materials, and seem far more photo-stable - I've seen sharpies fade to nothing after a few weeks in sunlight (on plant labels) but I have things that have lasted years labelled with these pens.
A further test with a fatter permanent OHP pen (red, same series) suggests that allowing it to dry for a minute or so is a good idea.
The finer pen seems to withstand hard rubbing better than the broader one, partly, I suspect, because it marks deeper into the foam (as the pressure is distributed over a much smaller area).
Do be sure to get the permanent sort, not the water-based washable ones. Denatured alcohol will take most permanent markers off smooth surfaces if necessary, but on foam would just make a mess