EDIT: Try passing an id to the before select, as shown here:

var rect1 = group.insert("svg:rect", "#foreign_object")

You cannot select by element tag name, only by constants (such as an id), as specified in the docs:

The name and before selector must be specified as constants, though in the future we might allow inserting of existing elements or a function to generate the name or selector dynamically.

Related Query

More Query from same tag