V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
工单节点使用指南
• 请用平和的语言准确描述你所遇到的问题
• 厂商的技术支持和你一样也是有喜怒哀乐的普通人类,尊重是相互的
• 如果是关于 V2EX 本身的问题反馈,请使用 反馈 节点
longjiahui
V2EX  ›  全球工单系统

请问朋友们一个 puppeteer 的问题

  •  
  •   longjiahui · 2020-03-16 04:27:01 +08:00 · 891 次点击
    这是一个创建于 1506 天前的主题,其中的信息可能已经有所发展或是发生改变。

    请问 puppeteer 能不能 在 page goto 一个非标准 scheme 的 uri 时做 interception 代码如下,无法在page.on('request', xxx)中监听到 request。 而是直接报错

    const puppeteer = require('puppeteer-core');
    const findChrome = require('./findChrome');
    
    (async ()=>{
        const { executablePath, type } = await findChrome({});
        if (!executablePath) {
          console.error('Could not find Chrome installation, please make sure Chrome browser is installed from https://www.google.com/chrome/.');
          process.exit(0);
          return;
        }
      
        const browser = await puppeteer.launch({
            executablePath,
            headless: false,
            defaultViewport: null,
            userDataDir: '.local-data',
        });
        let pages = await browser.pages();
        let page = pages[0];
        page.on('request', (request)=>{
            console.log(request); // 👈 到达不了这里
            request.continue();
        });
        page.on('requestfinished', (request)=>{
            console.log(request);
        })
        await page.setRequestInterception(true);
        try{
            await page.goto('app://index.html');
        }catch(err){
            console.error(err);
        }
    })();
    

    报错信息:

    Error: net::ERR_ABORTED at app://index.html
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2545 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 11:29 · PVG 19:29 · LAX 04:29 · JFK 07:29
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.