From f1c771282d0652c2b57a9b9c23317b6962ecd56e Mon Sep 17 00:00:00 2001 From: dragongoose <19649813+dragongoose@users.noreply.github.com> Date: Tue, 7 Mar 2023 17:54:53 -0500 Subject: [PATCH] add optimizations --- server/package.json | 2 ++ server/routes/profile/profileRoute.ts | 32 +++++++++++++-------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/server/package.json b/server/package.json index b0f52d7..c45dbbd 100644 --- a/server/package.json +++ b/server/package.json @@ -5,6 +5,8 @@ "dotenv": "^16.0.3", "express": "^4.18.2", "puppeteer": "^19.7.2", + "puppeteer-extra": "^3.3.6", + "puppeteer-extra-plugin-adblocker": "^2.13.6", "winston": "^3.8.2" }, "devDependencies": { diff --git a/server/routes/profile/profileRoute.ts b/server/routes/profile/profileRoute.ts index 27ca976..91c6ffd 100644 --- a/server/routes/profile/profileRoute.ts +++ b/server/routes/profile/profileRoute.ts @@ -1,8 +1,14 @@ import { Router } from 'express' -import puppeteer, { Browser, Page } from 'puppeteer' +import puppeteer from 'puppeteer-extra' +import { Browser, Page } from 'puppeteer' +import { PuppeteerExtraPluginAdblocker } from 'puppeteer-extra-plugin-adblocker' import { LooseObject } from '../../types/looseTypes' import { Streamlink } from '@dragongoose/streamlink' +puppeteer.use(new PuppeteerExtraPluginAdblocker({ + blockTrackersAndAnnoyances: true +})) + const profileRouter = Router() export interface Socials { @@ -30,6 +36,7 @@ export interface StreamerData { stream?: StreamData } + const abbreviatedNumberToNumber = (num: string) => { const base = parseFloat(num) @@ -65,22 +72,13 @@ const withBrowser = async (fn: Function) => { const withPage = (browser: Browser) => async (fn: Function) => { const page = await browser.newPage(); - //turns request interceptor on - await page.setRequestInterception(true); - - //if the page makes a request to a resource type of image or stylesheet then abort that request - page.on('request', request => { - if (request.resourceType() === 'image') - request.abort(); - else - request.continue(); - }); - - try { - return await fn(page); - } finally { - await page.close(); - } + //await page.tracing.start({ path: '../profile.json', screenshots: true }); + try { + return await fn(page); + } finally { + //await page.tracing.stop(); + await page.close(); + } } let isLive: boolean