You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何切换至Chrome非活动标签页?Windows10下Python3.x直接跳转指定标签

Windows 10 Python 3.x 切换Google Meet Chrome标签方案

前置准备

1. 开启Chrome远程调试功能

右键Chrome桌面快捷方式,选择「属性」,在「目标」输入框的原有内容末尾添加一个空格,再加上参数:
--remote-debugging-port=9222
保存后关闭所有Chrome进程,重新通过这个快捷方式启动Chrome生效。

2. 安装依赖库

执行命令安装需要的第三方库:
pip install pychrome pywin32

实现代码

import win32gui
import win32con
import pychrome

# 连接本地Chrome调试接口
browser = pychrome.Browser(url="http://127.0.0.1:9222")

# 直接调用Chrome原生接口过滤Google Meet标签,无需本地遍历
targets = browser.call_method("Target.getTargets", filter={
    "type": "page",
    "url": "*meet.google.com*"
})["targetInfos"]

if targets:
    # 取第一个匹配的目标标签(提问中说明是唯一存在的)
    meet_target = targets[0]
    # 激活目标标签
    browser.call_method("Target.activateTarget", targetId=meet_target["targetId"])
    
    # 将Chrome窗口切换到前台获得焦点
    chrome_hwnd = win32gui.FindWindow("Chrome_WidgetWin_1", None)
    if chrome_hwnd:
        win32gui.ShowWindow(chrome_hwnd, win32con.SW_RESTORE)
        win32gui.SetForegroundWindow(chrome_hwnd)

说明

  • 过滤逻辑完全由Chrome内核执行,Python侧不需要遍历所有标签,仅获取匹配后的结果,符合需求要求
  • 可以根据实际情况调整过滤规则,比如需要匹配标题的话可以把过滤条件改为"title": "*Google Meet*"
  • 如果打开Chrome时没有加远程调试参数,会出现连接失败的报错

内容的提问来源于stack exchange,提问作者Twiffy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 20:36:05