0% found this document useful (0 votes)
35 views4 pages

CODIGOS

This document is a JavaScript module that uses Puppeteer to automate browser tasks with stealth capabilities and random user agents for iPhone. It allows for the creation of multiple browser instances with specified resolutions and proxies, handling browser disconnections and re-establishing connections as needed. The module also includes a function to generate unique session IDs for each browsing session.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views4 pages

CODIGOS

This document is a JavaScript module that uses Puppeteer to automate browser tasks with stealth capabilities and random user agents for iPhone. It allows for the creation of multiple browser instances with specified resolutions and proxies, handling browser disconnections and re-establishing connections as needed. The module also includes a function to generate unique session IDs for each browsing session.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

const puppeteer = require('puppeteer-extra');

const StealthPlugin = require('puppeteer-extra-plugin-stealth');


const randomUseragent = require('random-useragent');
const useProxy = require('puppeteer-page-proxy');
const { HttpProxyAgent } = require('http-proxy-agent');

puppeteer.use(StealthPlugin());

module.exports = {
async start(numTabs, configs) {
const resolutions = [
{ width: 1920, height: 1080 },
{ width: 1600, height: 900 },
{ width: 1366, height: 768 },
{ width: 1280, height: 720 },
{ width: 1440, height: 900 },
{ width: 1440, height: 1080 },
{ width: 1680, height: 1050 },
{ width: 1920, height: 1200 },
];

const iPhoneUserAgents = [
'Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X) AppleWebKit/605.1.15
(KHTML, like Gecko) Version/14.0 Mobile/15E148 Safari/604.1',
'Mozilla/5.0 (iPhone; CPU iPhone OS 13_0 like Mac OS X) AppleWebKit/605.1.15
(KHTML, like Gecko) Version/13.0 Mobile/15E148 Safari/604.1',
'Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) AppleWebKit/605.1.15
(KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1',
// Adicione outros User-Agents de iPhones aqui, se desejar
];

let browsers = await Promise.all(


Array.from({ length: numTabs }, async () => {
let randomResolution = configs.randomResolutions ?
resolutions[Math.floor(Math.random() * resolutions.length)] : { width: 1920,
height: 1080 };
let useragent = randomUseragent.getRandom(function (ua) {
return ua.osName === 'iOS' && ua.userAgent.includes('iPhone');
});
let browser = await puppeteer.launch({
headless: false,
args: [
'--start-maximized',
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-infobars',
--user-agent=${useragent},
--window-size=${randomResolution.width},${randomResolution.height},
'--blink-settings=imagesEnabled=true'
]
});

return browser;
})
);

let minport = 20001;


let maxport = 30000;
let pages = await Promise.all(browsers.map(browser => browser.newPage()));
await Promise.all(pages.map(async (page, index) => {
let useragent = randomUseragent.getRandom(function (ua) {
return ua.osName === 'iOS' && ua.userAgent.includes('iPhone');
});

const sessionId = generateSessionId();


const username = user-lu9039000-region-br;
const password = 'amigo1010';
const proxy = 'pr.lunaproxy.com:12233';
const proxyUrl = http://${username}:${password}@${proxy};
const agent = new HttpProxyAgent(proxyUrl);
let proxyHref = agent.proxy.href;

await useProxy(page, `${proxyHref}`);

if (browsers[index].isConnected()) {
try {
await page.setUserAgent(useragent);
await page.goto(configs.url, { waitUntil: 'networkidle0', timeout:
60000 });
} catch (error) {
// console.error('Ocorreu um timeout de navegação', error);
}
} else {
console.log('Error: browser disconnected before navigating to page');
}
}));

await new Promise(resolve => setTimeout(resolve, 2000));

while (true) {
const isClosed = await Promise.all(browsers.map(browser =>
browser.isConnected()));
const numBrowsers = browsers.length;
const numOpenBrowsers = isClosed.filter(closed => closed).length;
const numMissingBrowsers = numTabs - numOpenBrowsers;

if (numMissingBrowsers > 0) {
const newBrowsers = await Promise.all(
Array.from({ length: numMissingBrowsers }, async () => {
let randomResolution = resolutions[Math.floor(Math.random() *
resolutions.length)];

let useragent = randomUseragent.getRandom(function (ua) {


return ua.osName === 'iOS' && ua.userAgent.includes('iPhone');
});

let browser = await puppeteer.launch({


headless: false,
args: [
'--start-maximized',
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-infobars',
--user-agent=${useragent},
--window-size=${randomResolution.width},${randomResolution.height},
'--blink-settings=imagesEnabled=true'
]
});

return browser;
})
);

browsers = browsers.concat(newBrowsers);

const newPages = await Promise.all(newBrowsers.map(browser =>


browser.newPage()));
await Promise.all(newPages.map(async(page, index) => {

let useragent = randomUseragent.getRandom(function (ua) {


return ua.osName === 'iOS' && ua.userAgent.includes('iPhone');
});

const sessionId = generateSessionId();


const username = user-lu9039000-region-br;
const password = 'amigo1010';
const proxy = 'pr.lunaproxy.com:12233';
const proxyUrl = http://${username}:${password}@${proxy};
const agent = new HttpProxyAgent(proxyUrl);
let proxyHref = agent.proxy.href;

await useProxy(page, `${proxyHref}`);

if (newBrowsers[index].isConnected()) {
try {
await page.setUserAgent(useragent);
await page.goto(configs.url, { waitUntil: 'networkidle0', timeout:
60000 });
} catch (error) {
// console.error('Ocorreu um timeout de navegação', error);
}
} else {
console.log('Error: browser disconnected before navigating to page');
}

}));
}

await new Promise(resolve => setTimeout(resolve, 2000));


}

},
};

function generateSessionId() {
const prefix = 'br417';
const characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
let sessionId = prefix;
for (let i = 0; i < 17 - prefix.length; i++) {
sessionId += characters.charAt(Math.floor(Math.random() * characters.length));
}
return sessionId;
}

You might also like