【问题标题】:Use DevTools protocol to open new tab in window使用 DevTools 协议在窗口中打开新选项卡
【发布时间】:2018-02-01 10:52:37
【问题描述】:

我正在使用 puppeteer 启动一个新的 Chrome 浏览器窗口:

const util = require('util');
const puppeteer = require('puppeteer');

(async () => {

  const b = await puppeteer.launch({
    headless: false,
    devtools: true, // open DevTools when window launches
    args: ['--remote-debugging-port=9222']
  });

  console.log('browser:', util.inspect(b));

  const c = await puppeteer.connect({
    browserWSEndpoint:   b._connection._url,   //`ws://${host}:${port}/devtools/browser/<id>`,
    ignoreHTTPSErrors: false
  });

  console.log('connection =>', c);

})();

我的问题是 - 我如何使用 websocket 连接 c 将 DevTools 协议消息发送到浏览器窗口?我想打开一个新标签,并执行一些其他操作。有人知道怎么做吗?

【问题讨论】:

    标签: node.js google-chrome puppeteer


    【解决方案1】:

    尚未对其进行测试,但从文档中阅读您可以执行以下操作:

    const client = await page.target().createCDPSession();
    await client.send('Target.createTarget', {'https://stackoverflow.com'});
    

    你可以找到:

    • CPDSession 的文档here
    • Chrome 开发工具协议的文档here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-18
      • 1970-01-01
      相关资源
      最近更新 更多