Update directives.js

Sometimes the window is loaded already.