From 04407fb6b2ce3108814ed480a0fffef372b1559b Mon Sep 17 00:00:00 2001 From: Rogee Date: Wed, 30 Sep 2026 12:50:19 +0800 Subject: [PATCH] =?UTF-8?q?feat(gateway):=20=E6=89=AB=E7=A0=81=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E9=BB=98=E8=AE=A4=E6=89=93=E5=BC=80=20douyin.com/user?= =?UTF-8?q?/self=20=E4=B8=AA=E4=BA=BA=E4=B8=AD=E5=BF=83=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 未登录访问会引导登录,登录后浏览器停留在账号个人中心(用户指定页面,替代原首页) --- browser_gateway/platform/douyin.py | 4 +++- browser_gateway/test_gateway.py | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/browser_gateway/platform/douyin.py b/browser_gateway/platform/douyin.py index 537d428..52a90a5 100644 --- a/browser_gateway/platform/douyin.py +++ b/browser_gateway/platform/douyin.py @@ -38,6 +38,8 @@ from ..runtime import ALIAS_RE LOG = logging.getLogger("creatorhub.douyin") ORIGIN = "https://www.douyin.com" ORIGIN_URL = ORIGIN + "/" +# 扫码登录默认打开个人中心页:未登录访问会引导登录,登录后即停在账号个人中心。 +LOGIN_PAGE_URL = ORIGIN + "/user/self" LOGIN_ORIGINS = frozenset( {ORIGIN, "https://sso.douyin.com", "https://verify.snssdk.com", "https://verify.bytedance.com"} ) @@ -379,7 +381,7 @@ class DouyinBrowser: def login_qr(self, alias: str) -> BrowserLoginQRResponse: with self.connection(alias) as cdp: - navigation = cdp.command("Page.navigate", {"url": ORIGIN_URL}) + navigation = cdp.command("Page.navigate", {"url": LOGIN_PAGE_URL}) if ( not isinstance(navigation, dict) or not isinstance(navigation.get("frameId"), str) diff --git a/browser_gateway/test_gateway.py b/browser_gateway/test_gateway.py index ff58587..a8144ae 100644 --- a/browser_gateway/test_gateway.py +++ b/browser_gateway/test_gateway.py @@ -22,6 +22,7 @@ from .platform.douyin import ( DouyinBrowser, DouyinError, DouyinSubscription, + LOGIN_PAGE_URL, ORIGIN_URL, SubscriptionManager, ack_expression, @@ -848,6 +849,10 @@ class BrowserTests(unittest.TestCase): "Page.captureScreenshot", ], ) + self.assertEqual( + cdp.command.call_args_list[0].args, + ("Page.navigate", {"url": LOGIN_PAGE_URL}), + ) self.assertFalse(any("cookie" in expression.lower() for expression in cdp.evaluate.call_args.args)) def test_connect_selects_configured_target_from_large_mixed_list(self) -> None: