41 lines
1.8 KiB
JavaScript
41 lines
1.8 KiB
JavaScript
// import puppeteer from 'puppeteer';
|
|
import puppeteer from 'puppeteer-extra';
|
|
import CONSTANTS from './constants.js';
|
|
import StealthPlugin from 'puppeteer-extra-plugin-stealth';
|
|
|
|
puppeteer.use(StealthPlugin());
|
|
const browser = await puppeteer.launch({
|
|
headless: process.env.ENVIRONMENT === 'prod' ? 'new' : false,
|
|
// userDataDir: CONSTANTS.PROFILE_PATH, // Thư mục lưu profile
|
|
timeout: 60000,
|
|
args: [
|
|
'--no-sandbox',
|
|
'--disable-setuid-sandbox',
|
|
'--disable-dev-shm-usage',
|
|
'--disable-gpu',
|
|
'--disable-software-rasterizer',
|
|
'--disable-background-networking',
|
|
'--disable-sync',
|
|
'--mute-audio',
|
|
'--no-first-run',
|
|
'--no-default-browser-check',
|
|
'--ignore-certificate-errors',
|
|
'--start-maximized',
|
|
'--disable-site-isolation-trials', // Tắt sandbox riêng cho từng site
|
|
'--memory-pressure-off', // Tắt cơ chế bảo vệ bộ nhớ
|
|
'--disk-cache-size=0', // Không dùng cache để giảm bộ nhớ
|
|
'--enable-low-end-device-mode', // Kích hoạt chế độ tiết kiệm RAM
|
|
'--disable-best-effort-tasks', // Tắt tác vụ không quan trọng
|
|
'--disable-accelerated-2d-canvas', // Không dùng GPU để vẽ canvas
|
|
'--disable-threaded-animation', // Giảm animation chạy trên nhiều thread
|
|
'--disable-threaded-scrolling', // Tắt cuộn trang đa luồng
|
|
'--disable-logging', // Tắt log debug
|
|
'--blink-settings=imagesEnabled=false', // Không tải hình ảnh,
|
|
'--disable-background-timer-throttling', // Tránh việc throttling các timer khi chạy nền.
|
|
'--disable-webrtc',
|
|
'--disable-ipc-flooding-protection', // Nếu có extension cần IPC, cái này giúp tối ưu.
|
|
],
|
|
});
|
|
|
|
export default browser;
|