Hi,
I have a usecase similar to codepen.io where people can write their own javascript and it will execute for others on page. Security considerations are handled the same way but unfortunately I can't reliably handle the case where somebody writes while(true) and crashes the browser of anyone that navigates to the page. In fact this piece of code makes my PC (Windows 11) almost entirely unresponsive altogether.
function callback(records) {
const lastRecord = records[records.length - 1];
console.log(`Current pressure ${lastRecord.state}`);
if (lastRecord.state === "critical") {
console.log("critical")
window.location.href = "/";
} else if (lastRecord.state === "serious") {
console.log("serious")
window.location.href = "/";
} else {
console.log("everything fine", lastRecord)
}
}
try {
//@ts-ignore
const observer = new PressureObserver(callback);
await observer.observe("cpu", {
sampleInterval: 1,
});
} catch (error) {
console.log("error", error)
}
while (true) {
console.log("XXXXXXXXXXXXXXXXXXXXXXXXX")
}
Idea 1: Shouldn't the compute pressure API be able to react to pressure no matter how high it is and let me e.g reload the page consistently or interrupt the page entirely somehow? Because even if I somehow get a window.location.href = "/" off while this while(true) loop is running, it will not manage to reload the page because the pressure is just too high.
Idea 2: Or is another idea perhaps that the compute pressure API should let me put a maximum pressure value on the e.g mainthread or even on other webworkers? I think we just need some way to not let the browser go into total crash mode just because one script has decided to take every single nanosecond of available CPU power.
Hi,
I have a usecase similar to codepen.io where people can write their own javascript and it will execute for others on page. Security considerations are handled the same way but unfortunately I can't reliably handle the case where somebody writes while(true) and crashes the browser of anyone that navigates to the page. In fact this piece of code makes my PC (Windows 11) almost entirely unresponsive altogether.
Idea 1: Shouldn't the compute pressure API be able to react to pressure no matter how high it is and let me e.g reload the page consistently or interrupt the page entirely somehow? Because even if I somehow get a window.location.href = "/" off while this while(true) loop is running, it will not manage to reload the page because the pressure is just too high.
Idea 2: Or is another idea perhaps that the compute pressure API should let me put a maximum pressure value on the e.g mainthread or even on other webworkers? I think we just need some way to not let the browser go into total crash mode just because one script has decided to take every single nanosecond of available CPU power.