js_enabled属性是 Splash 的 JavaScript 执行开关,可以将其配置为 true 或 false 来控制是否执行 JavaScript 代码,默认为 true 。例如,这里禁止执行 JavaScript 代码:
function main(splash, args) splash:go("https://www.baidu.com") splash.js_enabled = false # 这里禁止运行JavaScript脚本 local title = splash:evaljs("document.title") # 这里再运行JavaScript脚本就会报错 return {title=title} end
执行后,抛出如下异常:
{ "description": "Error happened while executing Lua script", "info": { "js_error_message": null, "type": "JS_ERROR", "error": "unknown JS error: None", "message": "[string "function main(splash, args) ..."]:4: unknown JS error: None", "source": "[string "function main(splash, args) ..."]", "line_number": 4, "splash_method": "evaljs" }, "type": "ScriptError", "error": 400 }