如何修复“错误:执行上下文被破坏,很可能是由于导航错误”?

时间:2019-07-15 23:33:15

标签: node.js puppeteer

我正在尝试通过操纵up进行SSO身份验证。登录后,URL重定向到原始页面。登录完成并且页面完全加载后,我想获取页面的内容。我越来越 Execution context was destroyed, most likely because of a navigation错误。哪个执行上下文被破坏了?重定向后如何获取页面的内容?

/*
Get reponse for a URL
 */
let getPageResponse = async function (url, cookies, timeout) {
    try {

        let browser = await puppeteer.launch({headless: false});
        let page = await browser.newPage();
        const response = await page.goto(url, {'timeout': timeout, 'waitUntil': ['load', 'networkidle0']});
        let currentUrl = page.url();

        await page.type("#uname", secrets.id);
        await page.type("#pwd", secrets.password);
        let [responseNew] = await Promise.all([
            page.waitForNavigation({'timeout': 30000, 'waitUntil': ['load', 'networkidle0']}),
            page.click(handleInfo.element),
        ]);

        let content = await page.content();

        console.log("<<"+content);
    }
    catch (e) {
        console.log('<<<<< ERROR' + e);
    } finally {
    }

0 个答案:

没有答案