-
Notifications
You must be signed in to change notification settings - Fork 359
Expand file tree
/
Copy pathcreate_har.py
More file actions
40 lines (28 loc) · 1.22 KB
/
create_har.py
File metadata and controls
40 lines (28 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import asyncio
import json
from playwright.async_api import async_playwright
def filter_sensitive_info(request):
sensitive_headers = ["Authorization", "Cookie"]
filtered_headers = [
header for header in request.headers if header["name"] not in sensitive_headers
]
request.headers = filtered_headers
async def open_browser_and_wait():
async with async_playwright() as p:
browser = await p.chromium.launch(headless=False)
context = await browser.new_context(
record_har_path="filtered_network_requests.har", # Path to save the filtered HAR file
record_har_content="embed", # Omit content to make the HAR file smaller
)
page = await context.new_page()
context.on("request", filter_sensitive_info)
print(
"Browser is open. Press Enter in the terminal when you're ready to close the browser and save cookies..."
)
input("Press Enter to continue and close the browser...")
cookies = await context.cookies()
with open("filtered_cookies.json", "w") as f:
json.dump(cookies, f, indent=4)
await context.close()
await browser.close()
asyncio.run(open_browser_and_wait())