返回列表

Chrome dev tools fails to show This "Failed load response data" chrome.devtools.network.getHAR()

默认分类 2019/12/05 10:19

问题描述:

在chrome下,audio 通过 canplaythrough 事件切换 src 等待加载完毕,再通过下面的方法获取响应内容,

chrome.devtools.network.getHAR(function(harLog) {}) 

然后再

req.getContent(function(content, encoding) {})

发现有一些 content 为空,然后网上找了一些资料,Chrome dev tools fails to show This "Failed load response data"

也没找到好的解决方案,于是尝试不再通过改变src而是每次都创建audio,发现问题解决。

代码如下:

'use strict'
var wlist = [
    'kendra',
    'opting',
    'sergei',
    'terrorists',
    'couturiers',
    'amphitheatre',
    'kuldeep',
    'freelancing',
    'saddam']

var page = {}
page.aIndex = 1

page.next = function () {
  if (page.status === 'stop') return ''

  var link = wlist.pop()
  if (!link) return console.log(new Date())
  var elem = page.getAudio()
  elem.status = 'doing'
  elem.src = 'http://dict.youdao.com/dictvoice?audio=' + link + '&type=2'
}

page.inited = false
page.getAudio = function () {
  var elem = document.createElement('AUDIO')
  // elem.controls = true
  elem.id = 'au' + (page.aIndex++)
  elem.preload = 'auto'
  elem.addEventListener('canplaythrough', function() {
    if (!page.inited) page.next()
    var elem = this
    window.setTimeout(function(){
      if (!page.inited) console.log(document.querySelectorAll('audio').length)
      page.inited = true

      document.body.removeChild(elem)
      page.next()
    }, 2000)
  })
  document.body.append(elem)
  elem.ready = true
  return elem
}

page.start = function () {
  console.log(new Date())
  page.next()
  page.next()
  page.next()
  page.next()
}


>> 留言评论