Tell Puppeteer to open Chrome tab instead of window

て烟熏妆下的殇ゞ 提交于 2020-07-06 20:33:16

问题


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?

I have:

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');

})();

回答1:


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.



来源:https://stackoverflow.com/questions/48218584/tell-puppeteer-to-open-chrome-tab-instead-of-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!