Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: 前端每十秒save的event发送到controller, data要怎样正确拼接才可以正确回放, 现在我只能播放前十秒, 之后因为拼接出错, 一直播放失败 #1473

Open
1 task done
98549844 opened this issue May 12, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@98549844
Copy link

Preflight Checklist

  • I have searched the issue tracker for a bug report that matches the one I want to file, without success.

What package is this bug report for?

rrweb

Version

2.0.0

Expected Behavior

[Bug]: 前端每十秒save的event发送到controller, data要怎样正确拼接才可以正确回放,

1.保存js
rrweb.record({
emit(event) {
// 用任意方式存储 event
console.log(event);
events.push(event);
},
});

    // rrweb行为录制
    let events = [];

    // 每 10 秒调用一次 save 方法,避免请求过多
    setInterval(save, 10 * 1000);

    // save 函数用于将 events 发送至后端存入,并重置 events 数组
    function save() {
        const body = JSON.stringify(events);
        // if (events.length === 0) {
        //     return;
        // }
        events = []; // 重置 events 数组
        fetch("/rest/rrweb/save.html", {
            method: "POST",
            headers: {
                "Content-Type": "application/json",
            },
            body: body,
        });
    }

2.回放js
function replay() {
let playbackId = 'playback-id';
$.ajax({
type: "GET",
url: "/rest/rrweb/playback/" + playbackId, //访问的链接
dataType: 'json',
success: function (resp) { //成功的回调函数
const records = JSON.parse(resp.data);
new rrwebPlayer({
target: document.getElementById("rrweb-player"),
data: {
events: records,
},
});
},
error: function (e) {
console.log("error:" + e.message);
}
});
}

  1. 后端controller部分

    StringBuilder tmp;

    @operation(summary = "保存记录")
    @RequestMapping(method = RequestMethod.POST, value = "/save.html")
    public AjaxResponse save(@RequestBody String data) {
    tmp = new StringBuilder();
    tmp.append(data);
    return AjaxResponse.success(data);
    }

    @operation(summary = "回放")
    @RequestMapping(method = RequestMethod.GET, value = "/playback/{playbackId}")
    public AjaxResponse playback(@PathVariable String playbackId) {
    log.info("access RRWeb playbackId: {}", playbackId);
    return AjaxResponse.success(tmp.toString());
    // return tmp;
    }

Actual Behavior

现在我只能播放前十秒, 之后因为拼接出错, 一直播放失败

Steps to Reproduce

  1. 进入页面, 每十秒自动保存
  2. 每十秒发送到后台,
  3. 后台拼接, 并等待前端调用 (拼接数据出错), 所以只能播前十秒, 超过十秒都播放失败

Testcase Gist URL

No response

Additional Information

No response

@98549844 98549844 added the bug Something isn't working label May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant