告诉Puppeteer打开Chrome标签页而不是窗口 [英] Tell Puppeteer to open Chrome tab instead of window

查看:717
本文介绍了告诉Puppeteer打开Chrome标签页而不是窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我打开了一个现有的Google Chrome窗口,我想告诉puppeteer打开一个新标签,而不是打开一个新窗口.有没有办法做到这一点?我可以传递给伪造者一些选项或标志来做到这一点吗?

If I have an existing Google Chrome window open, I'd like to tell puppeteer to open a new tab instead of opening a new window. Is there a way to do that? is there some option or flag I can pass to puppeteer to accomplish this?

我有:

const puppeteer = require('puppeteer');

(async function () {

  const b = await puppeteer.launch({
    devtools: true,
    openInExistingWindow: true /// ? something like this?
  });

  const page = await b.newPage();
  await page.goto('https://example.com');

})();

推荐答案

const browser = puppeteer.launch();
const page = browser.newPage();

这实际上将在当前浏览器实例上打开一个新选项卡. 您可以在此处检出页面类文档和浏览器类文档此处.

This will actually open a new tab on your current browser instance. You can checkout the page class docs here and the browser class docs here.

这篇关于告诉Puppeteer打开Chrome标签页而不是窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆