简体   繁体   English

如何从Web Worker访问chrome.history?

[英]How can I access chrome.history from a Web Worker?

Is there any way I can access the chrome.* apis (specifically chrome.history ) from a Web Worker? 有什么方法可以从Web Worker访问chrome。* api(特别是chrome.history )?

If I pass the chrome.history or chrome object in with postMessage , it is not working because of a conversion error to Transferable type. 如果我将chrome.history或chrome对象传递给postMessage ,则由于无法转换为Transferable类型而无法正常工作。

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). Web Workers应当是轻量级的,并且不会从扩展继承任何权限( 甚至不继承主机权限 )(此外,Web Worker中甚至没有定义chrome )。

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). 如果您正在使用chrome.history API的结果做大量工作,则可以将回调的结果传递给工作程序进行处理(使用Transferables,开销很小)。 Before doing that, make sure that you profile whether the performance impact is really that significant to warrant implementing anything like this. 在执行此操作之前,请确保配置文件对性能的影响是否真的如此重要,以保证可以实施此类操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM