Skip to content

Instantly share code, notes, and snippets.

@achmel
Last active November 26, 2025 17:18
Show Gist options
  • Select an option

  • Save achmel/e189ad4b8b4e28c235796994fe2cb68e to your computer and use it in GitHub Desktop.

Select an option

Save achmel/e189ad4b8b4e28c235796994fe2cb68e to your computer and use it in GitHub Desktop.
Tiny parser to get websocket messages from Google Chrome Developer Tools > Network > Export HAR...
# !/usr/bin/env python3
# encoding: utf-8
import json
file_name = 'websocket.har'
f = open(file_name)
j = json.load(f)
entries = j['log']['entries']
for e in entries:
if e['_resourceType'] == 'websocket' and '_webSocketMessages' in e.keys():
messages = e['_webSocketMessages']
for m in messages:
if len(m['data']) > 1:
print(m)
@dylan-tactus
Copy link

I think the shebang is wrong, it needs the space removed before the "!".

This line:

# !/usr/bin/env python3

Should be changed to:

#!/usr/bin/env python3

In it's current state, if I chmod u+x chrome_websocket_messages.py then ./chrome_websocket_messages.py I think bash can't read the shebang and guesses that it should run the file with imagemagick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment