import json, time
from fb_common import COOKIES_JSON, driver
arr = json.load(open(COOKIES_JSON, encoding="utf-8"))
if isinstance(arr, dict): arr = arr.get("cookies", [])
fb = [c for c in arr if "facebook" in (c.get("domain","") or "")]
d = driver()
d.get("https://www.facebook.com/"); time.sleep(2)
for c in fb:
    p = {"name":c.get("name"),"value":c.get("value",""),"domain":c.get("domain"),
         "path":c.get("path","/") or "/","secure":bool(c.get("secure",True)),
         "httpOnly":bool(c.get("httpOnly",False))}
    ss=(c.get("sameSite") or "").lower()
    p["sameSite"]={"no_restriction":"None","none":"None","lax":"Lax","strict":"Strict"}.get(ss,"Lax")
    try: d.execute_cdp_cmd("Network.setCookie", p)
    except Exception: print("fail",c.get("name"))
names_before = sorted(c["name"] for c in d.get_cookies())
print("avant nav: c_user=", "c_user" in names_before, "xs=", "xs" in names_before)
d.get("https://www.facebook.com/"); time.sleep(4)
html = d.page_source
names_after = sorted(c["name"] for c in d.get_cookies())
login_form = ('name="email"' in html) or ('Connexion ou inscription' in html)
print("apres nav: c_user=", "c_user" in names_after, "login_form=", login_form)
print("URL:", d.current_url)
print("indices:", {"QuoiDeNeuf":"Quoi de neuf" in html or "What" in html,
                   "menuCompte": "Déconnexion" in html or "Se déconnecter" in html,
                   "DTSG":"DTSGInitialData" in html})
d.quit()
