A foam seal won't stop carbon monoxide.
No, it’s not safe.
Carbon monoxide is odorless and will seep through any gap, even a compressed foam seal. A partially open door with a foam strip still lets enough air exchange to put you and your family at risk. On top of that, the garage door can pinch or wear through the extension cord insulation over time, creating a fire or shock hazard.
Generator exhaust needs to be far away from any opening into your home — windows, doors, vents. The only safe way to run a cord into a garage is through a professionally installed through-wall pass-through, or better yet, keep the generator entirely outside and well away from the structure.
This is not where you take shortcuts.