I am using mitmproxy for debugging purposes and I want to display the captured request URL in almost real-time through a GUI framework. The following is my add-on script:
import threading
import pygame
from mitmproxy import http
# initialize pygame
pygame.init()
screen = pygame.display.set_mode((500, 200))
pygame.display.set_caption("mitmproxy and pygame Example")
# shared url_queue
url_queue = []
def request(flow: http.HTTPFlow):
print(flow.request.url)
url_queue.append(flow.request.url)
def display_url():
screen.fill((255, 255, 255))
font = pygame.font.Font(None, 24)
# display url
for i, url in enumerate(url_queue):
text = font.render(url, True, (0, 0, 0))
screen.blit(text, (20, 20 + i * 30))
pygame.display.flip()
def main():
running = True
clock = pygame.time.Clock()
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
display_url()
clock.tick(30)
pygame.quit()
threading.Thread(target=main).start()
After executing mitmdump.exe -s addon_tmp.py
, mitmdump console output as expected, but the pygame window became unresponsive and failed to display any content.
How can I achieve the purpose?