appreciate some assistance on the following issue, which seems to be from Stealth Plugin. I am using puppeteer to click on a download button in an iframe, which works when I am using Puppeteer, but not when I am using Stealth Plugin.
The problem: Once the button is clicked, nothing happens, no download is initiated.
Basically, removing puppeteer.use(StealthPlugin()) makes the entire code work. However I need Stealth Plugin to avoid being detection as an automation browser.
Libraries
Work/Doesn't work
Puppeteer
Works
Puppeteer-extra
Works
Puppeteer-extra + Stealth Plugin
Doesn't work
Following is a simplified code which I am using:
const puppeteer = require("puppeteer-extra");
const StealthPlugin = require("puppeteer-extra-plugin-stealth");
puppeteer.use(StealthPlugin());
(async () => {
//Setup the browser
const browser = await puppeteer.launch({
headless: false,
ignoreHTTPSErrors: true,
args: ["--ignore-certificate-errors"],
});
const page = await browser.newPage();
await page._client.send("Page.setDownloadBehavior", {
//Initial setup for download
behavior: "allow",
downloadPath: downloadPath,
});
await page.setViewport({ width: 1366, height: 768 });
await page.goto("***websitehere***");
await page.waitForTimeout(3000);
const frameElement = await page.$("#iframe-analytics");
const frame = await frameElement.contentFrame();
await frame.waitForSelector(".table-download-button");
await frame.click(".table-download-button");
await browser.close();
})();
Button which I'm trying to click on:
<button class="table-download-button md-icon-button md-button ng-scope md-scionTheme-theme md-ink-ripple" type="button" ng-transclude="" ng-if="ctrl.csvFormatter" ng-click="ctrl.downloadCsv()" aria-label="Download CSV" md-labeled-by-tooltip="md-tooltip-19">
<md-icon md-font-set="material-icons-extended" class="material-icons-extended ng-scope md-scionTheme-theme" aria-hidden="true" role="img">save_alt</md-icon>
<div class="md-ripple-container"></div></button>
Would appreciate if someone could point out what other setting I have to change that's unique on puppeteer extra + stealth plugin.
Related
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?
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});