Skip to content

Commit

Permalink
use new headless browser
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredcat committed May 3, 2023
1 parent 025bd4f commit 8291624
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 25 deletions.
130 changes: 124 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"eslint-plugin-unused-imports": "^2.0.0",
"husky": "^8.0.3",
"jest": "^29.5.0",
"rimraf": "^3.0.2",
"rimraf": "^4.4.1",
"ts-jest": "^29.1.0",
"typescript": "^4.9.3"
}
Expand Down
6 changes: 3 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import url from "node:url";

import puppeteer from "puppeteer-extra";
import StealthPlugin from "puppeteer-extra-plugin-stealth";

puppeteer.use(StealthPlugin());

import {render} from "ink";
Expand Down Expand Up @@ -490,7 +489,8 @@ async function main(): Promise<void> {
"--disable-backgrounding-occluded-windows",
"--disable-renderer-backgrounding",
"--window-size=1920,1080",
"--disable-features=HardwareMediaKeyHandling"
"--disable-features=HardwareMediaKeyHandling",
"--disable-blink-features=AutomationControlled"
];

function getArgNames(args: string[]) {
Expand Down Expand Up @@ -556,7 +556,7 @@ async function main(): Promise<void> {

// Start browser
const browser = await puppeteer.launch({
headless: config["headless"],
headless: config["headless"] ? "new": false,
executablePath: config["browser"],
args: config["browser_args"]
});
Expand Down
26 changes: 13 additions & 13 deletions src/twitch_drops_bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {TwitchDropsWatchdog} from "./watchdog.js";
import {StreamPage} from "./pages/stream.js";
import utils, {TimedSet, waitForResponseDataWithOperationName} from "./utils.js";
import logger from "./logger.js";
import {Client, TimeBasedDrop, DropCampaign, StreamTag, getInventoryDrop, FreeformTag, Inventory, isDropCompleted, getStreamUrl} from "./twitch.js";
import {Client, TimeBasedDrop, DropCampaign, StreamTag, getInventoryDrop, Inventory, isDropCompleted, getStreamUrl} from "./twitch.js";
import {NoStreamsError, NoProgressError, HighPriorityError, StreamLoadFailedError, StreamDownError} from "./errors.js";
import {broadcasterComparator, endTimeComparator, gameIndexComparator} from "./comparators.js";

Expand All @@ -35,15 +35,15 @@ function isDropReadyToClaim(drop: TimeBasedDrop): boolean {
return drop.self.currentMinutesWatched >= drop.requiredMinutesWatched;
}

function hasDropsEnabledTag(freeformTags: FreeformTag[]): boolean {
logger.debug("hasDropsEnabledTag tags: " + JSON.stringify(freeformTags));
for (const tag of freeformTags) {
if (tag.name.toLowerCase() === StreamTag.DROPS_ENABLED || tag.name.toLowerCase() === StreamTag.DROPS) {
return true;
}
}
return false;
}
// function hasDropsEnabledTag(freeformTags: FreeformTag[]): boolean {
// logger.debug("hasDropsEnabledTag tags: " + JSON.stringify(freeformTags));
// for (const tag of freeformTags) {
// if (tag.name.toLowerCase() === StreamTag.DROPS_ENABLED || tag.name.toLowerCase() === StreamTag.DROPS) {
// return true;
// }
// }
// return false;
// }

function createStreamUrl(broadcasterId: string): string {
return "https://www.twitch.tv/" + broadcasterId;
Expand Down Expand Up @@ -1066,9 +1066,9 @@ export class TwitchDropsBot extends EventEmitter {
logger.debug("user.stream: " + JSON.stringify(stream));

// Check if they have drops enabled
if (!hasDropsEnabledTag(stream.freeformTags)) {
continue;
}
// if (!hasDropsEnabledTag(stream.freeformTags)) {
// continue;
// }

// Check if they are streaming the correct game
const streamMetadata = await this.#twitchClient.getStreamMetadata(broadcasterId);
Expand Down
3 changes: 1 addition & 2 deletions src/update_games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import puppeteer from "puppeteer-extra";

// Add stealth plugin
import StealthPlugin from "puppeteer-extra-plugin-stealth";

puppeteer.use(StealthPlugin());

function onBrowserOrPageClosed() {
Expand Down Expand Up @@ -97,7 +96,7 @@ if (config["username"]) {

// Start browser and open a new tab.
const browser = await puppeteer.launch({
headless: config["headless"],
headless: config["headless"] ? "new" : false,
executablePath: config["browser"],
args: config["browser_args"]
});
Expand Down

0 comments on commit 8291624

Please sign in to comment.