From 420753f6e29abfc4116c3243f2ae905ac826b175 Mon Sep 17 00:00:00 2001 From: filesite Date: Fri, 10 May 2024 16:24:59 +0800 Subject: [PATCH] add browser config for bot --- bot/Bilibili.mjs | 8 ++++++-- bot/Douyin.mjs | 8 ++++++-- bot/HeroBot.mjs | 6 +++++- bot/Kuaishou.mjs | 8 ++++++-- bot/Xigua.mjs | 8 ++++++-- config.mjs | 6 +++++- 6 files changed, 34 insertions(+), 10 deletions(-) diff --git a/bot/Bilibili.mjs b/bot/Bilibili.mjs index daa80ab..4201818 100644 --- a/bot/Bilibili.mjs +++ b/bot/Bilibili.mjs @@ -10,7 +10,11 @@ class Bilibili extends HeroBot { let options = { userAgent: configs.userAgent, - viewport: configs.viewport + viewport: configs.viewport, + showChrome: configs.showChrome, + showChromeInteractions: configs.showChromeInteractions, + showDevtools: configs.showDevtools, + showChromeAlive: configs.showChromeAlive, }; if (this.heroServer) { @@ -42,7 +46,7 @@ class Bilibili extends HeroBot { text => text != '', ); } - }); + }, {timeoutMs: configs.heroTabOptions.timeoutMs}); //解析网页HTML数据 data.title = await hero.document.title; diff --git a/bot/Douyin.mjs b/bot/Douyin.mjs index 74c2b51..d9c36a7 100644 --- a/bot/Douyin.mjs +++ b/bot/Douyin.mjs @@ -10,7 +10,11 @@ class Douyin extends HeroBot { let options = { userAgent: configs.userAgent, - viewport: configs.viewport + viewport: configs.viewport, + showChrome: configs.showChrome, + showChromeInteractions: configs.showChromeInteractions, + showDevtools: configs.showDevtools, + showChromeAlive: configs.showChromeAlive, }; if (this.heroServer) { @@ -42,7 +46,7 @@ class Douyin extends HeroBot { text => text != '', ); } - }); + }, {timeoutMs: configs.heroTabOptions.timeoutMs}); //解析网页HTML数据 data.title = await hero.document.title; diff --git a/bot/HeroBot.mjs b/bot/HeroBot.mjs index 14e6366..ba7a655 100644 --- a/bot/HeroBot.mjs +++ b/bot/HeroBot.mjs @@ -33,7 +33,11 @@ class HeroBot { let options = { userAgent: configs.userAgent, - viewport: configs.viewport + viewport: configs.viewport, + showChrome: configs.showChrome, + showChromeInteractions: configs.showChromeInteractions, + showDevtools: configs.showDevtools, + showChromeAlive: configs.showChromeAlive, }; if (this.heroServer) { diff --git a/bot/Kuaishou.mjs b/bot/Kuaishou.mjs index 945495e..e95bb46 100644 --- a/bot/Kuaishou.mjs +++ b/bot/Kuaishou.mjs @@ -10,7 +10,11 @@ class Kuaishou extends HeroBot { let options = { userAgent: configs.userAgent, - viewport: configs.viewport + viewport: configs.viewport, + showChrome: configs.showChrome, + showChromeInteractions: configs.showChromeInteractions, + showDevtools: configs.showDevtools, + showChromeAlive: configs.showChromeAlive, }; if (this.heroServer) { @@ -35,7 +39,7 @@ class Kuaishou extends HeroBot { //等待所有内容加载完成 const tab = await hero.activeTab; await tab.waitForLoad('AllContentLoaded', {timeoutMs: configs.heroTabOptions.timeoutMs}); - await hero.waitForPaintingStable(); + await hero.waitForPaintingStable({timeoutMs: configs.heroTabOptions.timeoutMs}); //解析网页HTML数据 data.title = await hero.document.title; diff --git a/bot/Xigua.mjs b/bot/Xigua.mjs index 394c22c..1bc2f5b 100644 --- a/bot/Xigua.mjs +++ b/bot/Xigua.mjs @@ -10,7 +10,11 @@ class Xigua extends HeroBot { let options = { userAgent: configs.userAgent, - viewport: configs.viewport + viewport: configs.viewport, + showChrome: configs.showChrome, + showChromeInteractions: configs.showChromeInteractions, + showDevtools: configs.showDevtools, + showChromeAlive: configs.showChromeAlive, }; if (this.heroServer) { @@ -35,7 +39,7 @@ class Xigua extends HeroBot { //等待所有内容加载完成 const tab = await hero.activeTab; await tab.waitForLoad('AllContentLoaded', {timeoutMs: configs.heroTabOptions.timeoutMs}); - await hero.waitForPaintingStable(); + await hero.waitForPaintingStable({timeoutMs: configs.heroTabOptions.timeoutMs}); //解析网页HTML数据 data.title = await hero.document.title; diff --git a/config.mjs b/config.mjs index a9dfba9..8f42809 100644 --- a/config.mjs +++ b/config.mjs @@ -32,6 +32,10 @@ let configs = { width: 1440, height: 900 }, + showChrome: false, + showChromeInteractions: false, + showDevtools: false, + showChromeAlive: false, viewports: { mob: { @@ -46,7 +50,7 @@ let configs = { //请求参数 heroBotOptions: { - timeoutMs: 30000, + timeoutMs: 60000, referrer: '', },