我如何从Web Worker访问chrome.history? [英] How can I access chrome.history from a Web Worker?

查看:132
本文介绍了我如何从Web Worker访问chrome.history?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


$ b $有什么方法可以访问chrome b

如果我使用 postMessage 传入chrome.history或chrome对象,则由于转换错误为 Transferable type。



我可以成功地从我的扩展中查询历史记录并传递结果,但是我想让工作人员离开而不是主线程,然后传递结果。

解决方案

Web Workers意味着轻量级,并且不会继承任何权限(甚至没有托管权限)(此外, chrome 甚至没有在网络工作者中定义)。

如果您使用 chrome.history API的结果做了非常沉重的事情,那么您可以通过回收到工作人员进行处理的结果(使用Transferables,开销很小)。在此之前,请确保您分析性能影响是否确实非常重要,以保证实施此类功能。


Is there any way I can access the chrome.* apis (specifically chrome.history) from a Web Worker?

If I pass the chrome.history or chrome object in with postMessage, it is not working because of a conversion error to Transferable type.

I can successfully query the history from my extension and pass the results, but I would like to leave the heavy lifting to the worker instead of the main thread and then pass the results.

解决方案

Web Workers are meant to be light-weight, and do not inherit any permissions (not even host permissions) from the extension (besides, chrome is not even defined in a Web worker).

If you're doing really heavy stuff with the results of the chrome.history API, then you could pass the result of a callback to a worker for processing (with Transferables, the overhead is minimal). Before doing that, make sure that you profile whether the performance impact is really that significant to warrant implementing anything like this.

这篇关于我如何从Web Worker访问chrome.history?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆