cleanup: make _get_js_source function more robust