importjsonimportosfromtypingimportDictfromoffice365.sharepoint.client_contextimportClientContextdefload_cookies_from_storage_state(path:str)->Dict[str,str]:"""Load cookies exported by Playwright storage_state.json and extract SPO cookies. The library does not depend on Playwright; this is a helper to demonstrate usage. """withopen(path,"r",encoding="utf-8")asf:data=json.load(f)cookies={}forcindata.get("cookies",[]):name=c.get("name")ifnamein{"FedAuth","rtFa","SPOIDCRL"}:cookies[name]=c.get("value","")returncookiesif__name__=="__main__":site_url=os.environ.get("SP_SITE_URL","https://contoso.sharepoint.com/sites/demo")storage_state_path=os.environ.get("PLAYWRIGHT_STORAGE_STATE","./storage_state.json")defcookie_source():returnload_cookies_from_storage_state(storage_state_path)ctx=ClientContext(site_url).with_cookies(cookie_source)web=ctx.web.get().execute_query()print(f"Web title: {web.title}")