externalscript: Fix crash in case of no active document

BUG: 339010