Looks like script is not evaluated sometimes. Just simple script like `window.alert("debug");` don't work sometimes. On suckless.org it evaluates only when I go there with ^g, not when I start `surf suckless.org`.
Probably binding JS evaluation to "window-object-cleared" is wrong. I don't know when it is called (maybe before there is any document object?), there is almost no documentation on WebKit. Also JS evaluating function throws no exception when there is no alert (just added some checking code).