Why does it say undefined when i preload scene

<%- include(versionCheckTemplate, { version: ‘1.0.0’ }) %>
let cc;

export class Application {
constructor() {
this.settingsPath = '<%= settingsJsonPath %>';
    this.showFPS = <%= showFPS %>;
        }

        init(engine) {
        cc = engine;
        // THAY ĐỔI 1: Đổi sự kiện lắng nghe thành 'onPreBaseInitDelegate' để khớp với file kết quả.
        cc.game.onPreBaseInitDelegate.add(this.onPreBaseInit.bind(this));
        }



        onPreBaseInit() {
        // do custom logic
        var initPercent = Math.floor(Math.random() * 10) + 1;
        var progressBar = document.getElementById("progress-bar-fg");
        var loadingText = document.getElementById("loading-text");

        // Thêm kiểm tra để tránh lỗi nếu không tìm thấy phần tử DOM
        if (progressBar) {
        progressBar.style.width = initPercent + "%";
        }
        if (loadingText) {
        loadingText.innerHTML = "Đang tải: " + initPercent + "%";
        }
        }

        start() {
        return cc.game.init({
        debugMode: <%= debugMode %> ? cc.DebugMode.INFO : cc.DebugMode.ERROR,
            settingsPath: this.settingsPath,
            overrideSettings: {
            profiling: {
            showFPS: this.showFPS,
            }
            }
            }).then(() => {

            var previousPercent = 0;

            function setLoadingDisplay() {
            var splash = document.getElementById("splash");
            var progressBar = document.getElementById("progress-bar-fg");
            var loadingText = document.getElementById("loading-text");


            console.log("Đang tải scene...", cc.game );

            cc.director.preloadScene("HomeScene",
            function (completedCount, totalCount, item) {
            console.log(`Loaded ${completedCount}/${totalCount}`, item?.url);
            var percent = 100 * completedCount / totalCount;
            percent = percent.toFixed(0);


            if (progressBar && percent > previousPercent && percent >= 10) {
            progressBar.style.width = percent + "%";
            loadingText.innerHTML = "Đang tải: " + percent + "%";
            }

            previousPercent = percent;

   
            if (percent > 90) {
            if (progressBar) progressBar.style.width = "100%";
            if (splash) splash.style.display = "none";
            }
            },
            function (err) {
       
            console.error("Lỗi khi tải scene: ", err);
            }
            );
            }

            if (cc.sys.isBrowser) {
            setLoadingDisplay();
            }


            cc.game.run();
            });
            }
            }

{84227438-A25A-4F2D-A7E5-90E5595ECCD4}
CC3.8.5

@Tom_k pls help me!

{FF370D26-C9CF-4E1D-8049-E25C87D6607E}

Maybe the resources of the scene have not been loaded. You can try to set a delay for preload.

Normally if you want to optimize the first load of web-mobile, what method do you use? @Tom_k