You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Maestro脚本报错:Cannot modify a property of a sealed object: arr

解决Maestro脚本中"Cannot modify a property of a sealed object: arr"错误

错误的核心原因是你在readPro函数中没有使用let/const声明arr、o、filtered这些变量,导致它们被挂载到全局对象上。而Maestro的Rhino运行环境中,全局对象是**密封(sealed)**的,不允许添加或修改其属性,因此触发了这个异常。

修复方案

在函数内部对所有变量添加let或const声明,将它们转为局部变量,避免污染全局作用域。

修改后的fetch.js代码

const response = http.get('http://localhost:9999/api/device-screen')
const elements = json(response.body).elements

function readPro(json, replaceText, props, filter, resorceIdFinal){
  let arr = [], o = {}

  json.forEach(
      el => {
          const resorceId = el.resourceId.replace(replaceText, '')
          if(props.includes(resorceId)){
              o[resorceId] = el.text
              if(resorceId === resorceIdFinal){ 
                  arr.push(o)
                  o = {}
              }
          }
      }
  )

  const filtered = arr.reverse().filter(
      (s => o => 
          (k => !s.has(k) && s.add(k))
          (filter.map(k => o[k]).join('|'))
      )
      (new Set)
  )
  return filtered
}

const res = readPro(
  elements, 
  'com.shazam.android:id/',
  ['title', 'subtitle', 'datetime'],
  ['title', 'subtitle'],
  'datetime'
)

output.result = res

额外说明:resorceId和res变量也补充了声明,养成显式声明变量的习惯可以避免更多作用域相关的潜在问题。

内容的提问来源于stack exchange,提问作者Paul

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 04:21:23