木偶无头:虚假的超时,真实的作品

时间:2019-04-20 16:11:06

标签: puppeteer google-chrome-headless

headless = true和headless = false之间存在差异的原因有哪些?请注意,这是在Mac 10.14.4上

环境

$ node -v
v11.14.0

$ npm v puppeteer | grep version
puppeteer@1.14.0 | Apache-2.0 | deps: 8 | versions: 613

$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.14.4
BuildVersion:   18E226

代码(无头)

const puppeteer = require('puppeteer');

(async () => {
    const browser = await puppeteer.launch({ headless: true, args: ["--fast-start", "--disable-extensions", "--no-sandbox"],
        executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' });
    const page = await browser.newPage();
    await page.goto('http://www.criis.com/cgi-bin/doc_search.cgi?COUNTY=sanfrancisco&YEARSEGMENT=current&TAB=3');

    await page.select('select[name="DOC_TYPE"]', '002'); 
    await page.$eval('input[id="dateboxA"]', el => el.value = '04012019');
    await page.$eval('input[id="dateboxB"]', el => el.value = '04202019');
    await page.click('input[type="submit"]');

    const resp = await page.waitForNavigation(); // wait for search results page to load
    console.log(resp);
    await browser.close();    
})();

错误消息

$ node headless.js 
(node:27750) UnhandledPromiseRejectionWarning: TimeoutError: Navigation Timeout Exceeded: 30000ms exceeded
    at Promise.then (/Users/ag/node_modules/puppeteer/lib/LifecycleWatcher.js:143:21)
  -- ASYNC --
    at Frame.<anonymous> (/Users/ag/node_modules/puppeteer/lib/helper.js:110:27)
    at Page.waitForNavigation (/Users/ag/node_modules/puppeteer/lib/Page.js:676:49)
    at Page.<anonymous> (/Users/ag/node_modules/puppeteer/lib/helper.js:111:23)
    at /Users/ag/github/real_estate/sf/headless.js:14:26
    at processTicksAndRejections (internal/process/task_queues.js:86:5)
(node:27750) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:27750) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

headless为假时输出

$ node headless.js 
Response {
  _client:
   CDPSession {
     _events:
      [Object: null prototype] {...

0 个答案:

没有答案