I would like to know how and if it is possible to use puppeteer-extra-plugin-stealth
inside of visual studio project.
As far as I read there is a project called: puppeteer sharp
but they didn't showed how to use the plugin stealth, as this is best browser which is not detectable as a "bot
".
In my other puppeteer .js file
compiled by Docker
I have this code to load installed puppeteer-extra-plugin-stealth
:
Docker puppeteer code:
const puppeteer = require('puppeteer-extra');
const stealthPlugin = require('puppeteer-extra-plugin-stealth');
const { IS_PROD } = require('../utils/constants');
puppeteer.use(stealthPlugin());
// In order to run chromium processes in parallel. https://github.com/puppeteer/puppeteer/issues/594#issuecomment-325919885
process.setMaxListeners(Infinity);
const getBrowserInstance = async (port) => {
const browser = await puppeteer.launch({
args: IS_PROD ? ['--no-sandbox', `--proxy-server=socks5://127.0.0.1:${port}`] : ['--no-sandbox'],
devtools: !IS_PROD,
executablePath: IS_PROD ? '/usr/bin/chromium-browser' : undefined,
});
const incognitoBrowserContext = browser.createIncognitoBrowserContext();
incognitoBrowserContext.close = browser.close;
return incognitoBrowserContext;
};
module.exports = {
getBrowserInstance,
};
BUT THIS is my C# Form where I don't know how to use or load or implement puppeteer-extra-plugin-stealth
My VS Code:
using PuppeteerSharp;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace pupe
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private async void button1_Click(object sender, EventArgs e)
{
await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);
var browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
Headless = true
});
var page = await browser.NewPageAsync();
await page.SetViewportAsync(new ViewPortOptions
{
Width = 1920,
Height = 1080
});
await page.GoToAsync("https://bot.sannysoft.com/");
await page.ScreenshotAsync("screens/test.png", new ScreenshotOptions { Type = ScreenshotType.Png });
MessageBox.Show("screen done!");
}
}
}
Adding the stealth plugin to puppeteer-sharp may not be as simple than on the NodeJS Version. A C# port of the puppeteer-extra which works with puppeteersharp exists. Check https://github.com/Overmiind/Puppeteer-sharp-extra.