-
-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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] 切换浏览器tab后不会继续输出 #2615
Comments
Thank you for raising an issue. We will investigate into the matter and get back to you as soon as possible. |
是最新版本吗? |
Is it the latest version? |
是最新版本 |
is the latest version |
@gaye746560359 麻烦录个屏看下。我这边复现不出来 |
@gaye746560359 Please record the screen and take a look. I can't reproduce it here |
但就算延迟理论上应该也不会停止输出的呀? |
But theoretically, even if there is a delay, the output will not stop? |
这位的意思应该就是切到后台时不会输出吧,切回来肯定是好的,会继续输出。 |
What this probably means is that there will be no output when switching to the background. It must be good to switch back. |
是的,是你说的这个意思。 |
Yes, that's what you meant. |
那感觉是不是使用 requestAnimationFrame 能解决? |
Is it possible to use requestAnimationFrame? |
按下面的代码测试,requestAnimationFrame 后台还是会休眠。 var t = performance.now();
function fun1() {
const _t = performance.now();
console.log(_t - t);
t = _t;
// 使用 requestAnimationFrame 模拟 setTimeout
requestAnimationFrame(() => {
setTimeoutRAF(fun1, 100);
});
}
function setTimeoutRAF(callback, delay) {
let startTime = performance.now();
function loop(currentTime) {
if (currentTime - startTime >= delay) {
callback();
return;
}
requestAnimationFrame(loop);
}
requestAnimationFrame(loop);
}
fun1(); |
Test according to the following code, requestAnimationFrame will still sleep in the background. var t = performance.now();
function fun1() {
const _t = performance.now();
console.log(_t - t);
t = _t;
// Use requestAnimationFrame to simulate setTimeout
requestAnimationFrame(() => {
setTimeoutRAF(fun1, 100);
});
}
function setTimeoutRAF(callback, delay) {
let startTime = performance.now();
function loop(currentTime) {
if (currentTime - startTime >= delay) {
callback();
return;
}
requestAnimationFrame(loop);
}
requestAnimationFrame(loop);
}
fun1(); |
按网上的方案,web worker 模拟可行。 const workerCode = URL.createObjectURL(
new Blob(
[
"self.addEventListener('message', (event) => {" +
"setInterval(() => {" +
"self.postMessage(new Date() * 1);" +
'}, 100);' +
'});',
],
{ type: 'text/javascript' }
)
);
// 创建 Worker 实例,并指定 Blob URL
const worker = new Worker(workerCode);
var t = new Date() * 1;
worker.onmessage = (event) => {
const _t = event.data;
console.log(_t - t);
t = _t;
};
worker.postMessage('start'); |
According to the online plan, web worker simulation is feasible. const workerCode = URL.createObjectURL(
newBlob(
[
"self.addEventListener('message', (event) => {" +
"setInterval(() => {" +
"self.postMessage(new Date() * 1);" +
'}, 100);' +
'});',
],
{ type: 'text/javascript' }
)
);
//Create a Worker instance and specify the Blob URL
const worker = new Worker(workerCode);
var t = new Date() * 1;
worker.onmessage = (event) => {
const _t = event.data;
console.log(_t - t);
t = _t;
};
worker.postMessage('start'); |
👋 @{{ author }} |
This issue is closed, If you have any questions, you can comment and reply. |
💻 Operating System
Windows
📦 Environment
Other
🌐 Browser
Chrome
🐛 Bug Description
切换浏览器tab后不会继续输出
🚦 Expected Behavior
No response
📷 Recurrence Steps
No response
📝 Additional Information
No response
The text was updated successfully, but these errors were encountered: