0

My current code opens the desired URL and rename the window to the string I prefer, but just update the page that is open to the browser and with that my personalized name is lost and the web page title is again:

import pygetwindow as gw
import subprocess
import ctypes
import time

def open_and_rename(url: str, new_title: str):
    windows_before = set(gw.getAllTitles())
    
    subprocess.Popen([r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe", '--new-window', url])
    time.sleep(1)
    
    windows_after = set(gw.getAllTitles())
    new_windows = windows_after - windows_before
    
    if new_windows:
        new_window_title = list(new_windows)[0]
        window = gw.getWindowsWithTitle(new_window_title)[0]
        hwnd = window._hWnd
        ctypes.windll.user32.SetWindowTextW(hwnd, new_title)
    else:
        print("new window not found")

open_and_rename("https://www.google.com/", "Test")

But my desire is that it works exactly like this function of browsers Chrome and Edge:

enter image description here

With this option you rename the window and this value becomes fixed regardless of what you do in the browser (this option you find by clicking with the right side of the mouse both in the top of the window and the same action on the window miniature leaving the mouse on it in the taskbar)

Is there a way to do this on Python + Windows 11 without using Python moving simulators and mouse clicks and keyboard typing?

3
  • maybe you could create browser extension for renaming window automatically - but this need to use JavaScript instead of Python. Eventually you could try it with extensions like Greasemonkey, Tampermonkey or similar Commented Aug 13 at 12:09
  • javascript - Change a pop-up window's title using a Tampermonkey script? - Stack Overflow Commented Aug 13 at 12:12
  • Have you tested if the chromium comand-line argument --window-name works with MS edge? Commented Aug 16 at 20:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.