"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkWebPack = void 0;
const index_1 = require("./index");
function checkWebPack(page, callback) {
    return __awaiter(this, void 0, void 0, function* () {
        const result = yield page
            .evaluate(() => {
            window.qtd_web_client = 0;
        })
            .catch(() => { });
        while (true) {
            yield page.waitForFunction('window.webpackChunkwhatsapp_web_client.length').catch();
            const result = yield page
                .evaluate(() => {
                const webPack = window.webpackChunkwhatsapp_web_client.length;
                const webPackLast = window.webpackChunkwhatsapp_web_client.length - 1;
                if (!window.webpackChunkwhatsapp_web_client[webPackLast][0].includes("parasitesnake") && window.qtd_web_client !== webPack) {
                    console.log(window.webpackChunkwhatsapp_web_client);
                    window.qtd_web_client = webPack;
                    return true;
                }
                return false;
            })
                .catch(() => { });
            if (result) {
                callback && callback(true);
            }
            yield (0, index_1.sleep)(3000);
        }
    });
}
exports.checkWebPack = checkWebPack;
//# sourceMappingURL=check-webpack.js.map