Search code examples
microsoft-edgechromium

How to use the cookies stored on a device for a headless session of chromium / edge?


I'm trying to make use of this https://github.com/adriancs2/HTML-PDF-Edge
Specifically:

using (var p = new Process())
            {
                p.StartInfo.UseShellExecute = true;
                p.StartInfo.FileName = "msedge";
                p.StartInfo.Arguments = $"--headless --user-data-dir --disable-gpu --run-all-compositor-stages-before-draw --print-to-pdf=\"{filePath}\" {url}";
                p.Start();
                p.WaitForExit();
            } 

My current issue is that when I run edge in headless mode, the cookies from my session (even with a non-headless browser open at the same time) do not translate into the headless session.
Resulting in my objective, export a bunch of HTML websites behind a simple auth, not work.

How can I "tell chromium/edge" to use the cookies stored on the PC?

Thanks,


Solution

  • Normally, you'll only need to specify your profile, the session of which contains the desired cookies. I can see you've specified --user-data-dir. But the problem is, the old headless mode seems to not respect the your profile.

    You can use the new headless mode which has been released recently. Just try: --headless=new. Then, you'll be able to find your stored cookies in your profile.