抖音开放平台Logo
开发者文档
“/”唤起搜索
控制台
  • JS API 列表
  • 基础
  • tt.canIUse
  • tt.canIPutStuffOverComponent
  • tt.base64ToArrayBuffer
  • tt.arrayBufferToBase64
  • tt.setPageInfo
  • 性能
  • tt.performance.createObserver
  • tt.performance.getEntries
  • tt.performance.getEntriesByName
  • tt.performance.getCurrentPageEntries
  • tt.performance.setBufferSize
  • PerformanceEntry
  • tt.performance.clearMarks
  • tt.performance.mark
  • tt.performance.getEntriesByPage
  • tt.performance.getEntriesByType
  • 线程
  • 窗口尺寸变化
  • 生命周期
  • 版本更新
  • 定时器
  • 应用级事件
  • 环境变量
  • TTML
  • 网络
  • 媒体
  • 地图
  • 文件
  • 数据缓存
  • 地理位置
  • 设备
  • 画布
  • 界面
  • 页面导航
  • 开放接口
  • 行业开放
  • 第三方平台
  • 其它
  • 生活服务(即将废弃)
  • 小程序智能体
  • tt.performance.createObserver

    收藏
    我的收藏
    基础库 2.81.0 开始支持本方法,低版本需做兼容处理。这是一个同步方法。
    创建全局性能事件监听器。

    语法

    tt.performance.createObserver(callback)

    参数说明

    callback

    类型
    默认值
    必填
    说明
    最低支持版本
    function
    订阅的性能节点被触发后,回调的函数
    2.81.0
    回调函数参数为 array 类型,array 的每一项为 object 类型,object 属性如下:
    属性
    类型
    默认值
    说明
    name
    string
    该 performance entry 的名字
    entryType
    string
    代表所上报的 performance metric 的 entryType 类型,例如 "mark"、"paint"
    startTime
    number
    metric 的上报时间
    duration
    number
    持续时间
    path
    string
    页面路径,仅 type 为 paint 和 evaluate 时才可能存在
    fileName
    string
    文件名,仅 name 为 app-service 存在
    packageName
    string
    包名字(分报名/主包为APP),仅 name 为 app-service 或者 miniprogram-package 存在
    packageSize
    number
    包大小,仅 name 为 miniprogram-package 存在
    navigationType
    string
    路由详细类型,仅 type 为 navigation 时存在
    referrerPath
    string
    页面跳转来源页面路径,仅 type 为 navigation 时存在
    uri
    string
    资源路径,仅 name 为 resource-timing 时存在
    initiatorType
    string
    资源类型(合法资源类型:image、open-data),仅 name 为 resource-timing 时存在
    transferSize
    number
    获取资源的大小,仅 name 为 resource-timing 时存在
    domainLookupStart
    string
    解析域名开始时间,仅 name 为 resource-timing 时存在
    domainLookupEnd
    string
    解析域名结束时间,仅 name 为 resource-timing 时存在

    返回值

    object 类型,属性如下
    属性名
    类型
    说明
    最低支持版本
    disconnect
    function
    取消 observe 的方法,取消订阅后,即使页面的性能节点被触发,createObserver 中的回调函数也不会再执行。
    2.81.0
    observe
    function
    开始监听性能节点的订阅函数,当传入的订阅类型的性能节点被触发后,createObserver 中的回调函数被会执行。
    2.81.0

    disconnect 函数说明

    参数说明
    返回值

    observe 函数说明

    参数说明
    属性名
    类型
    说明
    最低支持版本
    type
    string
    指标类型。不能和 entryTypes 同时使用
    2.81.0
    entryTypes
    string[]
    指标类型数组。不能和 type 同时使用。
    2.81.0
    目前支持的指标类型请参考 PerformanceEntry
    返回值

    扫码体验

    代码示例

    const performance = tt.performance; const performanceObserver = performance.createObserver((entryList) => { console.log(entryList); }); // 订阅特定类型的性能节点的两种方式 performanceObserver.observe({ entryTypes: ["paint", "evaluate", "navigation"],类型 }); // performanceObserver.observe({ type: 'paint' }); performanceObserver.disconnect();

    Bug & Tip

      Tip: observer 的入参只能是 entryTypes 或者 type 中的一个,禁止一起使用。