Skip to content
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

Usecase: 100% pressure, main thread blocked entirely. PressureObserver never fires an event #290

Open
Meai opened this issue Jul 21, 2024 · 0 comments

Comments

@Meai
Copy link

Meai commented Jul 21, 2024

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.

@Meai Meai changed the title Usecase: 100% pressure, main thread blocked entirely. Please let me react? Usecase: 100% pressure, main thread blocked entirely. PressureObserver never fires an event Jul 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant