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

Blob / ArrayBuffer 兼容性疑问 #153

Closed
the1812 opened this issue Nov 11, 2020 · 4 comments
Closed

Blob / ArrayBuffer 兼容性疑问 #153

the1812 opened this issue Nov 11, 2020 · 4 comments
Labels

Comments

@the1812
Copy link

the1812 commented Nov 11, 2020

你好, 我是 Bilibili-Evolved 的开发者, 最近在准备更新弹幕下载的功能 (xml 换成 proto), 但是发现开着 pakku 插件的时候, 调用 seg.so API 得到的 Blob 是个空对象, 请问如何做才能兼容 pakku 呢?

测试视频: https://www.bilibili.com/video/av92150659
Chrome 86.0.4240.183
pakku 10.0.4
Bilibili-Evolved 内部开发版 点此下载

未开启 pakku:
image

开启 pakku:
image

我项目中的相关代码:
https://github.com/the1812/Bilibili-Evolved/blob/e0a5080862dd647de009a4f57e315f749f1581cf/src/video/danmaku-converter/danmaku-segment.ts#L272-L296
https://github.com/the1812/Bilibili-Evolved/blob/e0a5080862dd647de009a4f57e315f749f1581cf/src/video/video-info.ts#L40-L64

pakku 中可能的相关代码:
https://github.com/xmcp/pakku.js/blob/master/pakkujs/assets/xhr_hook.js

@xmcp
Copy link
Owner

xmcp commented Nov 11, 2020

在chrome平台上,pakku魔改了播放器页面的xhr,检测到弹幕请求的时候会生成一个假的响应然后手动去调用 load 回调。(firefox提供了原生的修改响应的方法,所以firefox版的pakku没魔改xhr)

由于 xmlHttpRequest 用法很多,我又不太可能把整个 API 给 polyfill 一遍,因此现在只针对 B 站播放器用到的 API 进行了兼容,给第三方插件带来了很多坑 不好意思hhh。

没仔细看 bilibili-evolved 具体怎么发请求的,但总之把代码写得尽量贴合 B 站播放器就能避开这些坑。例如:

  • xhr.addEventListener('load', ()=>{...}) 而非 xhr.onload=()=>{...} 添加回调
  • 设置请求的 responseTypearraybuffer
  • 回调从 xhr.response 读取响应(是个 ArrayBuffer

注意 pakku 会把所有弹幕塞到第一个 segment 里,后续的 segment 都会返回空结果。

另外 pakku 目前没有 hook fetch,所以直接用 fetch 去请求弹幕可以避开以上所有坑 #=_=

@xmcp
Copy link
Owner

xmcp commented Nov 11, 2020

感觉现在兼容性的坑越来越大了,可能重写一下xhr_hook比较好……你有什么建议吗?

@xmcp xmcp added the question label Nov 11, 2020
@the1812
Copy link
Author

the1812 commented Nov 11, 2020

看了下类似功能的, 似乎也是把 XHR 功能重新写了一遍... (谁让 response 那些都是只读的
我先换成 fetch 了, 确实不冲突了, 感谢

@xmcp xmcp closed this as completed Nov 11, 2020
@fanthos
Copy link

fanthos commented Dec 11, 2020

试试javascript的Proxy功能?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants