I'm testing a Chrome extensions and in order to setup everything correctly I would like to know the tabId when a new tab is created
const browser = await puppeteer.launch({ ... });
const appPage = await browser.newPage();
await appPage.goto(appUrl, { waitUntil: 'load' });
// TAB ID??????
I checked the documentation of the Page object but there is nothing about a tabId. So my question is, is it possible to extract a tabId with Puppereer?
Related
I've previously been getting results from bing using Puppeteer, but I'm now receiving the below error.
This comes from the following code, which previously worked.
(async () => {
const puppeteer = require('puppeteer');
const browser = await puppeteer.launch({headless: false})
const page = await browser.newPage();
await page.goto("https://www.bing.com/search?q=example+searchterm", { waitUntil: 'networkidle2'})
})();
When I do the same search in my browser, I get thousands of pages of results. Any ideas what's going on here?
I have tried multiple examples to get the splitwise login but unable to get it working.
Although, I'm quite new to puppeteer but login felt a simple usecase for understanding puppeteer.
const puppeteer = require('puppeteer')
const screenshot = 'login.png';
(async () => {
const browser = await puppeteer.launch({headless: false})
const page = await browser.newPage()
await page.goto("https://www.splitwise.com/login", {
waitUntil: 'networkidle2'
});
await page.type('#user_session_email', 'atest')
await page.type('#user_session_password', 'test')
await page.click('[name="commit"]')
await page.waitForNavigation()
browser.close()
console.log('See screenshot: ' + screenshot)
})()
Unfortunately, the page has two forms with identical ids (but different classes) and these forms have inputs with identical ids as well. You just need more specific selectors:
await page.type('form.form-stacked #user_session_email', 'atest')
await page.type('form.form-stacked #user_session_password', 'test')
await page.click('form.form-stacked [name="commit"]')
This does not seem to be a puppeteer issue.
It seems that javascript code in page is actively blocking triggered events somehow.
Are you able to set these values using regular javascript in the console?
I'm developing an app using Angular js and i'm doing a a questionnaire component which has a lot of nested pages to develop, so instead of doing changes and then spends a lot of time to return to the same page and see the results - i was advised to use Puppeteer to simulate to automate to page navigation ... I've found many examples of Puppeteer that outputs a png file - but none that's simply open a URL...
Here is what i've tried so far...
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('http://cnn.com');
// await page.screenshot({path: 'example.png'});
//await browser.close();
})();
As you can see in my example - it didn't opened a new page...
I have a multipage form and am using puppeteer to test. Problem I have is that when I ask to click to the next button it does click through but it doesn't go to the next page of the form. I have tried waitforNavigation but it throws a timeout issue. I have tried to address the timeout issue but to no success.
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setViewport({ width: 1920, height: 1080 });
await page.goto('https://example.com/form/');
//await page.waitForNavigation({timeout: 10000, waitUntil: "load"}); // The promise resolves after navigation has finished
await page.click('#next_button_1'); // Clicking the link will indirectly cause a navigation
await page.setDefaultNavigationTimeout(0);
await page.waitForNavigation();
await page.screenshot({path: 'example.png',fullPage: true});
// other actions...
await browser.close();
})();
How to change headless from false to true ?
How to hide browser?
const browser = await puppeteer.launch({headless: false})
const page = await browser.newPage();
await page.goto(LOGIN_URL, { "waitUntil": "networkidle2" });
await page.evaluate((a) => {
$('input[name="username"]').val(a.username)
$('input[name="password"]').val(a.password)
}, {username, password})
// I want to hide the browser
// do something
await browser.close();
It is not possible to hide the browser in puppeteer at runtime — that's because Chromium can be launched either headless or non-headless only.
But during one script you can first run non-headless browser, close it and then open headless:
let browser = await puppeteer.launch({headless : false});
// 1. Enter requisites, log in to a site
// 2. Save cookies
await browser.close();
browser = await puppeteer.launch({headless : true});
// 3. Load cookies
// 4. Go and do headless stuff
Use this:
const browser = await puppeteer.launch({headless: true});