Firefox附加SDK页面工人阻止主线程 [英] firefox addon sdk page-worker blocks main thread
问题描述
我在后台抓取了大约20个网站,当一个页面在插件脚本中与页面工作器一起加载时。不幸的是浏览器冻结,在那段时间不可预知。
我尝试使用timers.setTimeout(...,0 - 400毫秒),并尝试从维基
函数executeSoon(aFunc){
var tm = Cc [@ mozilla.org/thread-manager;1 ]
.getService(Ci.nsIThreadManager);
tm.mainThread.dispatch({
run:function(){
aFunc();
}
},Ci.nsIThread.DISPATCH_NORMAL) ;
}
但是这也冻结了用户界面。有没有其他的解决方案?
抓取的代码:
..
timer.setTimeout(function(){
let pageWorker = require(sdk / page-worker)。Page({
contentScriptFile:self.data.url(js / (),
contentURL:url
));
pageWorker.port.on(loaded,function(content){
if(typeof callback ==='function'){
callback(content);
}
});
},200)
...
即使在更简单的情况下,extractor.js也会返回body.textContent,它将被阻止。 $ b
这是因为Firefox使用页面工作者的主线程,在Firefox每夜的内容页面使用单独的进程,这意味着页面工作人员将使用单独的过程,所以给 Firefox Nightly 一个尝试,它应该在那里工作,这将将在几个月内发布。
I'm crawling about 20 Web sites in the background, when a page loads, within the addon script, with the page-worker. Unfortunately the browser freezes, unpredictable during that time.
I tried to use timers.setTimeout(..., 0-400ms) and also tried the example from the wiki
function executeSoon(aFunc) {
var tm = Cc["@mozilla.org/thread-manager;1"]
.getService(Ci.nsIThreadManager);
tm.mainThread.dispatch({
run: function () {
aFunc();
}
}, Ci.nsIThread.DISPATCH_NORMAL);
}
but this also freezes the UI. Is there any other solution?
The crawling code:
...
timer.setTimeout(function () {
let pageWorker = require("sdk/page-worker").Page({
contentScriptFile: self.data.url("js/extractor.js"),
contentURL: url
});
pageWorker.port.on("loaded", function (content) {
if (typeof callback === 'function') {
callback(content);
}
});
}, 200)
...
The extractor.js, even in simpler cases, where it return body.textContent, is blocking.
This is because Firefox uses the main thread for page-workers, in Firefox nightly content pages uses separate processes, which means that page-workers will use a separate processes too, so give Firefox Nightly a try, it should work there, and this will be released in a few months.
这篇关于Firefox附加SDK页面工人阻止主线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!