It would be good to see the context of the svg, but the following worked for me with a pure SVG document:
shape = document.getElementsByTagName("svg")[0];
shape.setAttribute("viewBox", "-250 -250 500 750");
Maybe it’s because viewBox is case-sensitive?