Fix JS widget initialization

This does three things as detailed in the commit messages.

Fixes #1210 and #1211.