如何使用puppeter wsendpoint打开链接

时间:2017-11-09 10:59:58

标签: node.js google-chrome-headless puppeteer

我尝试将浏览器与wsendpoint连接起来:

(async () => {  


 const browser = await puppeteer.connect({browserWSEndpoint: 'ws://localhost:9222/devtools/page/eedbdd50-cd25-472d-a701-a0302d9ffe2f'});
  const page = await browser.newPage();
  await page.goto('https://www.google.com.tr');  
})();

此代码可以打开新标签但不要转到链接。它给出了错误:

(node:2022) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Protocol error (Performance.enable): 'Performance.enable' wasn't found undefined
(node:2022) [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.

1 个答案:

答案 0 :(得分:1)

试试这个:

const puppeteer = require('puppeteer');

puppeteer.connect({
  browserWSEndpoint: 'your endpoint...'
}).then(async browser => {
  const page = await browser.newPage();
  await page.goto('https://www.google.com.tr');
});