From 5ea1e9168f85b0d6dbf2f196503fabefb60c6eee Mon Sep 17 00:00:00 2001
From: Lluis <lluisdanes@gmail.com>
Date: Mon, 5 Feb 2024 21:51:01 +0100
Subject: [PATCH] fixes with browser

---
 handlers/stream.js  | 11 +++++++----
 services/browser.js |  6 ++++--
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/handlers/stream.js b/handlers/stream.js
index c2791c0..bfa093f 100644
--- a/handlers/stream.js
+++ b/handlers/stream.js
@@ -33,10 +33,13 @@ class Stream {
                 parse_mode: 'Markdown'
             }
 
-            await bot.sendMessage(config.telegram.chatId, text, options).then((msg) => {
-                     TwitchService.saveLastMessage(msg)
-                     TwitchService.saveTitle(result.title)
-                })
+            const msg = await bot.sendMessage(config.telegram.chatId, text, options)
+            try {
+                await bot.pinChatMessage(config.telegram.chatId, result.messageId)
+            } catch {}
+            await TwitchService.saveLastMessage(msg)
+            await TwitchService.saveTitle(result.title)
+
         } else if (result && result.type === 'finished' && result.messageId) {
             await bot.deleteMessage(config.telegram.chatId, result.messageId)
             await TwitchService.deleteLastMessage()
diff --git a/services/browser.js b/services/browser.js
index 39ae18c..ff37ef4 100644
--- a/services/browser.js
+++ b/services/browser.js
@@ -7,10 +7,12 @@ async function getScreenshot() {
         const browser = await puppeteer.connect({ browserWSEndpoint: `wss://${config.browserlessUrl}` })
         const page = await browser.newPage()
 
-        const session = await page.target().createCDPSession()
-        await session.send("Page.enable")
         await page.setViewport({ width: 1920, height: 1080 })
         await page.goto("https://www.twitch.tv/" + config.twitch.channels, { waitUntil: 'networkidle0' })
+
+        await page.$eval('button[data-a-target="consent-banner-accept"]', el =>  el.click())
+        await page.$eval('button[data-a-target="content-classification-gate-overlay-start-watching-button"]', el =>  el.click())
+
         await page.waitForSelector('div.persistent-player')
         await page.$eval('.video-player__default-player', el => el.remove())
         const svgImage = await page.$('div.persistent-player')