问题
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