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

如何通过subprocess修改Edge弹窗标题并规避iframe访问限制?

无需iframe修改Edge弹窗标题的可行方案

方案一:通过Chrome DevTools Protocol(CDP)注入脚本修改标题

  1. 启动Edge时同时指定--app和--remote-debugging-port参数,开启调试端口:
import subprocess
import requests
import json

# 启动带调试端口的Edge应用窗口
proc = subprocess.Popen([
    "msedge",
    "--app=https://目标直播网址",
    "--remote-debugging-port=9222"
])
  1. 通过CDP API获取页面目标并注入修改标题的JS:
# 获取当前页面的调试目标
response = requests.get("http://localhost:9222/json")
targets = response.json()
page_target = next(t for t in targets if t["type"] == "page")

# 发送修改标题的命令
requests.post(
    page_target["webSocketDebuggerUrl"].replace("ws://", "http://") + "/execute",
    json={
        "method": "Runtime.evaluate",
        "params": {
            "expression": 'document.title = "你的自定义标题"'
            # 若要动态获取直播标题,可改为类似:
            # 'document.title = document.querySelector(".live-title").textContent || "默认标题"'
        }
    }
)

注意:调试端口需确保未被占用,且目标页面加载完成后再执行注入操作。

方案二:加载极简Edge扩展修改标题

  1. 创建一个仅用于修改标题的极简扩展:
    • 新建目录,创建manifest.json:
{
  "manifest_version": 3,
  "name": "直播标题修改器",
  "version": "1.0",
  "content_scripts": [
    {
      "matches": ["https://目标直播网站域名/*"],
      "js": ["content.js"],
      "run_at": "document_start"
    }
  ]
}
  • 同目录下创建content.js:
// 直接设置固定标题,或根据页面内容动态生成
document.title = "自定义直播标题";
// 动态示例:获取页面内的直播名称元素文本作为标题
// const liveTitle = document.querySelector(".live-name")?.textContent || "未知直播";
// document.title = liveTitle;
  1. 启动Edge时加载该扩展并打开应用窗口:
import subprocess

subprocess.Popen([
    "msedge",
    "--app=https://目标直播网址",
    "--load-extension=/path/to/your/extension/directory"
])

注意:扩展目录需为绝对路径,且Edge需允许加载未打包的扩展(首次启动可能会弹出提示,需手动确认一次)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 11:14:51