-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplaywright_attach.py
More file actions
30 lines (23 loc) · 1.08 KB
/
Copy pathplaywright_attach.py
File metadata and controls
30 lines (23 loc) · 1.08 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
"""Launch a Morfiade profile and drive it with Playwright.
pip install morfiade playwright
The profile keeps its own cookies and proxy: Playwright attaches to the real
Chrome window instead of starting a clean browser of its own.
"""
import sys
from playwright.sync_api import sync_playwright
from morfiade import Morfiade
PROFILE = sys.argv[1] if len(sys.argv) > 1 else "shop-1"
api = Morfiade()
info = api.start(PROFILE)
if info.get("transport") != "port":
# "extension": no port on purpose, use extension_cdp.py instead;
# "none": tick Debug mode on the profile in Morfiade and restart it.
sys.exit("%s has no debugging port (transport %r): %s"
% (PROFILE, info.get("transport"), info.get("hint", "")))
with sync_playwright() as p:
browser = p.chromium.connect_over_cdp(info["ws"])
context = browser.contexts[0] # the profile's own context
page = context.pages[0] if context.pages else context.new_page()
page.goto("https://example.com/")
print(page.title())
browser.close() # detaches; the window stays open