mirror of
https://github.com/NikolaiT/se-scraper.git
synced 2025-08-09 05:54:38 +02:00
pluggable is now class
This commit is contained in:
@ -1,39 +1,46 @@
|
||||
module.exports = {
|
||||
get_browser: get_browser,
|
||||
handle_metadata: handle_metadata,
|
||||
close_browser: close_browser
|
||||
};
|
||||
module.exports = class Pluggable {
|
||||
constructor(options = {}) {
|
||||
const {
|
||||
chromeFlags = [
|
||||
'--no-sandbox',
|
||||
'--disable-setuid-sandbox',
|
||||
'--disable-dev-shm-usage',
|
||||
'--disable-accelerated-2d-canvas',
|
||||
'--disable-gpu',
|
||||
'--window-size=1920x1080',
|
||||
'--hide-scrollbars',
|
||||
'--user-agent=Chrome',
|
||||
],
|
||||
userAgent = 'Chrome',
|
||||
headless = true,
|
||||
} = options;
|
||||
|
||||
async function close_browser(browser) {
|
||||
await browser.close();
|
||||
}
|
||||
this.chromeFlags = chromeFlags;
|
||||
this.userAgent = userAgent;
|
||||
this.headless = headless;
|
||||
|
||||
async function handle_metadata() {
|
||||
// silence
|
||||
}
|
||||
this.chromeFlags.push(this.userAgent);
|
||||
}
|
||||
|
||||
async function get_browser(launch_args) {
|
||||
const puppeteer = require('puppeteer');
|
||||
async close_browser() {
|
||||
await this.browser.close();
|
||||
}
|
||||
|
||||
const ADDITIONAL_CHROME_FLAGS = [
|
||||
'--no-sandbox',
|
||||
'--disable-setuid-sandbox',
|
||||
'--disable-dev-shm-usage',
|
||||
'--disable-accelerated-2d-canvas',
|
||||
'--disable-gpu',
|
||||
'--window-size=1920x1080',
|
||||
'--hide-scrollbars',
|
||||
'--user-agent=Chrome',
|
||||
];
|
||||
async handle_metadata(args) {
|
||||
// silence
|
||||
}
|
||||
|
||||
let custom_args = {
|
||||
args: ADDITIONAL_CHROME_FLAGS,
|
||||
headless: true,
|
||||
};
|
||||
async start_browser(args={}) {
|
||||
const puppeteer = require('puppeteer');
|
||||
|
||||
browser = await puppeteer.launch(launch_args);
|
||||
let launch_args = {
|
||||
args: args.chromeFlags || this.chromeFlags,
|
||||
headless: args.headless || this.headless,
|
||||
};
|
||||
|
||||
console.log('Loaded custom function get_browser()');
|
||||
this.browser = await puppeteer.launch(launch_args);
|
||||
console.log('Loaded custom function get_browser()');
|
||||
|
||||
return browser;
|
||||
}
|
||||
return this.browser;
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user